在DT :: renderDataTable中添加下载按钮 [英] Add download buttons in DT::renderDataTable

查看:104
本文介绍了在DT :: renderDataTable中添加下载按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的R Shiny应用程序的表格上方添加下载按钮(复制, csv, excel, pdf),但是在内部使用数据表时,renderDataTable似乎不起作用。

I am trying to add download buttons ('copy', 'csv', 'excel', 'pdf') above the table in my R Shiny app, but the renderDataTable seems doesn't work when using a datatable inside.

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效果很好,并且除了下载按钮(我要添加的内容)之外,我具有所有功能(过滤器,搜索字段等)

When I use DT::renderDataTable without DT::datatable inside, renderDataTable works well and I have all features (filters, search field, etc), except download buttons (what I am trying to add)

output$mytable1 = DT::renderDataTable({ plots.dfs()[[1]] })

Do你有什么想法我做错了什么?感谢您的帮助

Do you have any idea of what I am doing wrong? Thanks for your help

推荐答案

正如Stephan在评论中所说,添加按钮的方式如下:

As Stephan said in comment, the way to add buttons is the following:

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"
                       ))

这篇关于在DT :: renderDataTable中添加下载按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆