【问题标题】:Is there a way to adapt datatable width with sidebar width in shinydashboard?有没有办法在闪亮仪表板中调整数据表宽度和侧边栏宽度?
【发布时间】:2020-09-07 12:33:35
【问题描述】:

我在下面有闪亮的仪表板,如您所见,我想在侧边栏中显示一个数据表,但问题是该表要宽得多。我可以在不增加侧边栏宽度的情况下使表格完全适合侧边栏吗?

library(shiny)
library(shinydashboard)
library(DT)
    ui <- dashboardPage(
      dashboardHeader(),
      dashboardSidebar(
        sidebarMenu(
          menuItem("Table" , tabname = "my_table", icon = icon("table"),DT::dataTableOutput("example_table")
                   ),
          menuItem("Next Widget", tabName = "Other"))),

      dashboardBody(
        tabItems(
          tabItem(tabName = "subMenu", #my_table",
                  fluidRow(
                  )),
          tabItem(tabName = "Other",
                  h2("Other tab")
          )
        )))
    server <- function(input, output) {
      output$example_table <- DT::renderDataTable(head(mtcars))
    }
    shinyApp(ui, server)

【问题讨论】:

    标签: r shiny datatables shinydashboard dt


    【解决方案1】:

    一种快速的方法是为您的DT 启用水平滚动。然后表格将适合容器但可以滚动:

    library(shiny)
    library(shinydashboard)
    ui <- dashboardPage(
      dashboardHeader(),
      dashboardSidebar(
        sidebarMenu(
          menuItem("Table" , tabname = "my_table", icon = icon("table"),DT::dataTableOutput("example_table")
          ),
          menuItem("Next Widget", tabName = "Other"))),
    
      dashboardBody(
        tabItems(
          tabItem(tabName = "subMenu", #my_table",
                  fluidRow(
                  )),
          tabItem(tabName = "Other",
                  h2("Other tab")
          )
        )))
    server <- function(input, output) {
      output$example_table <- DT::renderDataTable(head(mtcars), options = list(scrollX=TRUE))
    }
    shinyApp(ui, server)
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-02
      • 2016-12-05
      • 2012-03-14
      • 1970-01-01
      • 2020-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多