是否有一种方法可以使数据表的宽度与Shinydashboard中的边栏宽度相适应?

问题描述 投票:0回答:1

我下面有闪亮的仪表板,您看到了我想在侧边栏中显示数据表的问题,但问题是表的宽度要大得多。我可以在不增加sidbar宽度的情况下使桌子完全适合边栏吗?

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 shinydashboard dt
1个回答
0
投票

一种快速的方法是为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)

© www.soinside.com 2019 - 2024. All rights reserved.