r - 如何调整数据表的大小以将其放入闪亮仪表板的框()中
问题描述
我不知道如何确保我的 DT::renderDataTable 的大小适合我的盒子......
有人知道如何确保桌子适合盒子吗?或者我可以在表格下添加一个滑块来滚动屏幕上没有的其他变量吗?
这是我的代码:
服务器.R
output$table = DT::renderDataTable({
DT::datatable(
round(df,2),
rownames = TRUE,
extensions = 'Buttons',
options = list(
autoWidth = FALSE,
columnDefs = list(list(width = "125px", targets = "_all")),
dom = 'tpB',
lengthMenu = list(c(5, 15, -1), c('5', '15', 'All')),
pageLength = 15,
buttons = list(
list(
extend = "collection",
text = 'Show More',
action = DT::JS("function ( e, dt, node, config ) {
dt.page.len(50);
dt.ajax.reload();}")
),list(
extend = "collection",
text = 'Show Less',
action = DT::JS("function ( e, dt, node, config ) {
dt.page.len(10);
dt.ajax.reload();}")
)
)
)
)
})
身体.R
box( title = "A little taste of the dataset",
width = 12,
DT::dataTableOutput("table") )
提前致谢。
解决方案
您可以简单地添加scrollX = TRUE
到数据表选项:
library(shiny)
library(shinydashboard)
DF <- data.frame(replicate(50, runif(1000, 0, 10)))
ui <- fluidPage(box(
title = "A little taste of the dataset",
width = 12,
DT::dataTableOutput("myTable")
))
server <- function(input, output, session) {
output$myTable = DT::renderDataTable({
DT::datatable(
round(DF, 2),
rownames = TRUE,
extensions = 'Buttons',
options = list(
autoWidth = FALSE, scrollX = TRUE,
columnDefs = list(list(
width = "125px", targets = "_all"
)),
dom = 'tpB',
lengthMenu = list(c(5, 15,-1), c('5', '15', 'All')),
pageLength = 15,
buttons = list(
list(
extend = "collection",
text = 'Show More',
action = DT::JS(
"function ( e, dt, node, config ) {
dt.page.len(50);
dt.ajax.reload();}"
)
),
list(
extend = "collection",
text = 'Show Less',
action = DT::JS(
"function ( e, dt, node, config ) {
dt.page.len(10);
dt.ajax.reload();}"
)
)
)
)
)
})
}
shinyApp(ui = ui, server = server)
推荐阅读
- c# - 如何在word-addin的一段文本中定位一些单词
- python - TypeError:序列项0:预期的字符串,在python中找到的int
- c++ - 在 Windows 上使用 LLVM 时 CMake 无法正确链接静态库
- php - 在 Symfony 中渲染 JSON [特殊字符问题]
- python - `dbus-send` 和 Python 的 `dbus` 使用 Spotify 之间的差异
- pyspark - 在 Pipenv 中安装模块后的 ModuleNotFoundError - Pyspark
- flutter - searchDelegate 不响应 itemList
- reactjs - 我收到此错误:尝试导入错误:“initReactI18next”未从“react-i18next”导出。这就是我的 i18next.js 文件的样子
- java - Spring Boot 外部 Tomcat 文件上传
- python - 类型错误:new() 缺少 1 个必需的位置参数:'y'