有没有办法在 shinydashboard 中调整数据表宽度和侧边栏宽度?

Is there a way to adapt datatable width with sidebar width in shinydashboard?

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

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)

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

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)