在 ShinyDashboard 中调整 Box 内 DataTable 的高度
Resize height of DataTable inside a Box in ShinyDashboard
我正在尝试将一些数据表和直方图放在 Shiny Dashboard 中定义高度的框中,问题是当我固定高度(比方说,到 250)时,数据表超出了限制。
我知道我们有 "autowidth" 可与数据表一起使用,但还没有看到与高度相似的东西。我也尝试修复数据表的高度,但这对我也不起作用。此外,当我在较小的屏幕上打开 shiny 时,框会调整大小,但数据表不会。
这是问题的一个例子
library(shiny)
library(shinydashboard)
library(htmltools)
ui <- dashboardPage(skin = "black", title = "Dashboard",
dashboardHeader(title = "Dashboard"),
dashboardSidebar(width = 300),
dashboardBody(
tags$head(tags$style(HTML("
div.box {
text-align: center;
border-style: solid;
border-bottom-color:red;
border-left-color:red;
border-right-color:red;
border-top-color:red;
border-bottom-width:20px;
border-top-width:20px;
border-left-width:20px;
border-right-width:20px;
}
"))),
box(title = "Resume", width = 4, column(12, withSpinner(DT::dataTableOutput("tab"))),
align="center", status = "danger",solidHeader = T,height=250)
))
server <- function(input, output) {
output$tab <- DT::renderDataTable({
datatable(head(iris),options=list("autoWidth"=TRUE, "pagelength"=15,"scrollY"=TRUE,"scrollX"=TRUE,"searching"=FALSE))
})
}
# Run the application
shinyApp(ui = ui, server = server)
实际上 ScrollX 可以正常工作,为什么 scrollY 不能正常工作?
我阅读了有关使用 tabBox 而不是 Box 的信息,但这也不起作用。
非常感谢您。
尝试 withSpinner(DT::dataTableOutput("tab", height = '240px')
,目前您的代码正在设置框的高度,而不是数据 table。
此外,尝试 style = "overflow-x: scroll;"
在 box()
参数中滚动
我正在尝试将一些数据表和直方图放在 Shiny Dashboard 中定义高度的框中,问题是当我固定高度(比方说,到 250)时,数据表超出了限制。
我知道我们有 "autowidth" 可与数据表一起使用,但还没有看到与高度相似的东西。我也尝试修复数据表的高度,但这对我也不起作用。此外,当我在较小的屏幕上打开 shiny 时,框会调整大小,但数据表不会。
这是问题的一个例子
library(shiny)
library(shinydashboard)
library(htmltools)
ui <- dashboardPage(skin = "black", title = "Dashboard",
dashboardHeader(title = "Dashboard"),
dashboardSidebar(width = 300),
dashboardBody(
tags$head(tags$style(HTML("
div.box {
text-align: center;
border-style: solid;
border-bottom-color:red;
border-left-color:red;
border-right-color:red;
border-top-color:red;
border-bottom-width:20px;
border-top-width:20px;
border-left-width:20px;
border-right-width:20px;
}
"))),
box(title = "Resume", width = 4, column(12, withSpinner(DT::dataTableOutput("tab"))),
align="center", status = "danger",solidHeader = T,height=250)
))
server <- function(input, output) {
output$tab <- DT::renderDataTable({
datatable(head(iris),options=list("autoWidth"=TRUE, "pagelength"=15,"scrollY"=TRUE,"scrollX"=TRUE,"searching"=FALSE))
})
}
# Run the application
shinyApp(ui = ui, server = server)
实际上 ScrollX 可以正常工作,为什么 scrollY 不能正常工作? 我阅读了有关使用 tabBox 而不是 Box 的信息,但这也不起作用。 非常感谢您。
尝试 withSpinner(DT::dataTableOutput("tab", height = '240px')
,目前您的代码正在设置框的高度,而不是数据 table。
此外,尝试 style = "overflow-x: scroll;"
在 box()
参数中滚动