r - 在 DT::renderDataTable 中添加下载按钮
问题描述
我正在尝试在我的 R Shiny 应用程序的表格上方添加下载按钮('copy'、'csv'、'excel'、'pdf'),但是在内部使用数据表时,renderDataTable 似乎不起作用。
output$mytable1 <- DT::renderDataTable(
datatable(
{ plots.dfs()[[1]] },
rownames = TRUE,
options = list(
fixedColumns = TRUE,
autoWidth = TRUE,
ordering = FALSE,
dom = 'tB',
buttons = c('copy', 'csv', 'excel', 'pdf')
),
class = "display"
))
当我在没有 DT::datatable 的情况下使用 DT::renderDataTable 时,renderDataTable 运行良好,并且我拥有所有功能(过滤器、搜索字段等),除了下载按钮(我要添加的内容)
output$mytable1 = DT::renderDataTable({ plots.dfs()[[1]] })
你知道我做错了什么吗?谢谢你的帮助
解决方案
正如斯蒂芬在评论中所说,添加按钮的方式如下:
output$mytable1 <- DT::renderDataTable(
DT::datatable(
{ plots.dfs()[[1]] },
extensions = 'Buttons',
options = list(
paging = TRUE,
searching = TRUE,
fixedColumns = TRUE,
autoWidth = TRUE,
ordering = TRUE,
dom = 'tB',
buttons = c('copy', 'csv', 'excel')
),
class = "display"
))
推荐阅读
- javascript - 使用 jquery 显示带有 optgroup 选项名称的下拉值
- php - 如何在 php 中格式化 json 响应,然后在 js 文件中回显它
- java - 为什么 Kotlin sortBy() 似乎以相反的顺序运行?
- ruby-on-rails - true:TrueClass 的未定义方法“课程”
- r - 将置信区间添加到 R 中的摘要输出
- regex - 如何使用正则表达式在特定字符后获取 1 或 2 个字符?
- javascript - 使元素在另外两个类之间切换的简单而优雅的方法
- python - 在 Amazon Web Services 上创建 cron 作业的可扩展方式是什么?
- css - 滚动条宽度:无;VS 溢出-x:隐藏
- java - 您如何加载不在类路径中且在 jar 中的类?