使sidePaPanel自动滚动,使主屏幕处于闪亮状态

sir*_*len 3 css r shiny

我做了一个sidebarLayout in shiny,允许在溢出的情况下在mainPanel中滚动.sidebarPanel的位置保持固定,以便在向下滚动主面板时消失.但是,我希望它能够 mainPanel 一起滚动,这样用户就不需要再次向上滚动来更改设置.我该怎么做呢?

基本设置:

ui = fluidPage(

  tags$style(type='text/css', 'body { overflow-y: scroll; }'),

  titlePanel(
    # ...
  ),

  sidebarLayout(

    sidebarPanel(
      # ...
      width = 3),

    mainPanel(
      # ...

      width = 9 )

  ))

server = function(input,output,session) {

  # ...

}

shinyApp(ui=ui, server=server)
Run Code Online (Sandbox Code Playgroud)

Vic*_*orp 10

您可以添加style = "position:fixed;width:inherit;"到您sidebarPanel的元素中,但是您的元素将填充填充,宽度将恰好是页面的1/4(25%),例如,如果您希望侧边栏面板和主面板之间有更多空间,则需要22%.

例如:

library("shiny")

ui <- fluidPage(

  titlePanel(
    "Fixed sidebar panel"
  ),

  sidebarLayout(

    sidebarPanel(
      style = "position:fixed;width:inherit;",
      "Inputs",
      width = 3),


    mainPanel(

      lapply(
        X = 1:20,
        FUN = function(i) {
          plotOutput(outputId = paste("plot", i, sep = "-"))
        }
      ),

      width = 9 )

  ))

server <- function(input, output, session) {

  lapply(
    X = 1:20,
    FUN = function(i) {
      output[[paste("plot", i, sep = "-")]] <- renderPlot({plot(rnorm(10))})
    }
  )

}

shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)