r - 在 DT::renderDataTable 中添加下载按钮

标签 r shiny dt

我正在尝试在我的 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"
                       ))

关于r - 在 DT::renderDataTable 中添加下载按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50039186/

相关文章:

从plotreg()输出中删除框架并旋转标题

r - 如何在shiny app中播放本地视频?(Windows)

r - 为 Mac 创建 R 的可移植版本(并为此版本从源安装包)

javascript - 使用shinyjs通过javascript在 Shiny 的应用程序中操作现有的Leaflet map

javascript - 如何返回 R Shiny 中焦点元素的 ID?

r - 如何为数据表中的 'sparkline' 对象创建弹出窗口?

r - 将 R Markdown 发布到 Wordpress 时,不在 shorttag 中对内容进行 html 编码

r - 在同一个图中绘制两个图

r - 用于显示表格的 Shiny 模块

css - DT Shiny 不同的自定义列标题按列