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

时间:2017-05-15 06:19:34

标签: css r shiny

我制作了一个有光泽的sidebarLayout,允许在溢出的情况下在mainPanel中滚动。 sidebarPanel的位置保持固定,以便在向下滚动主面板时消失。但是,我希望用主屏幕滚动,这样用户就不需要再次向上滚动来更改设置。我该怎么做?

基本设置:

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)

1 个答案:

答案 0 :(得分:9)

您可以将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)