锁定R闪亮仪表板侧边栏(shinydashboard)

Hip*_*ian 6 r shiny

我在R中构建一个Shiny Dashboard时遇到困难(使用shinydashboard包).我想锁定我的侧边栏,以便在查看我的标签内容时不会滚动,但我不知道如何解决这个问题.

例如,以下代码块将创建一个长滚动的仪表板.锁定侧边栏会很好,这样您仍然可以在滚动浏览长度较长的数据表时看到菜单选项卡.

library(ggplot2)  ## for mpg dataset
library(shinydashboard)

## ui
ui <- dashboardPage(
  dashboardHeader(title="MPG Data"), 
  dashboardSidebar(sidebarMenu(menuItem("MPG", tabName="mpg"))), 
  dashboardBody(tabItems(tabItem(tabName="mpg", fluidRow(tableOutput("mpgTable"))))))

## server
server <- function(input, output) {
  output$mpgTable <- renderTable({mpg})
}

## launch dashboard 
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)

Car*_*eri 9

**免责声明:无论如何我都不是css专家

您可以在DT中为实际表设置选项,但是如果您希望实际仪表板中的选项卡可以从侧栏中自由滚动(假设您没有使用基于代码的导航栏),请为此提供一个镜头:

css看起来像这样:

.sidebar {
    color: #FFF;
    position: fixed;
    width: 220px;
    white-space: nowrap;
    overflow: visible;
}
Run Code Online (Sandbox Code Playgroud)

如果你的'www'文件夹中有.css文件,你可以从具有许多功能的ui中调用它; 所以我们假设您的文件名为"style.css".

ui现在看起来像这样:

dashboardPage(
  dashboardHeader(title="MPG Data"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("MPG",tabName="mpg")
    )
  ),
  dashboardBody(
    #here's where you throw the css into the header
    tags$head(
      includeCSS('www/style.css')
      ),
    tabItems(
      tabItem(tabName="mpg",
        fluidRow(tableOutput("mpgTable"))
        )
      )
    )
  )
Run Code Online (Sandbox Code Playgroud)

服务器端没有任何更改,但您可能希望使用DT检查或在表中设置选项以更轻松地处理数据.DT包参考

希望这可以帮助.


Edu*_*ler 7

你应该在ui侧边栏添加style ="position:fixed; overflow:visible".

library(ggplot2)  ## for mpg dataset
library(shinydashboard)

## ui
ui <- dashboardPage(
  dashboardHeader(title="MPG Data"), 
  dashboardSidebar(
    sidebarMenu(style = "position: fixed; overflow: visible;",
      menuItem("MPG", tabName="mpg"))), 
  dashboardBody(
    tabItems(
      tabItem(tabName="mpg", 
       fluidRow(tableOutput("mpgTable"))))))

## server
server <- function(input, output) {
  output$mpgTable <- renderTable({mpg})
}

## launch dashboard 
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)