按钮扩展名可下载所有数据或仅下载可见数据 [英] Button extension to download all data or only visible data
问题描述
使用DT包的按钮扩展名,可以指定按钮下载(1)提供给数据表的所有数据,还是(2)仅下载可见页面上的数据。
With the button extension to DT package, is there a way to specify that the buttons download either (1) all the data feeding the datatable, or (2) only the data on the visible page.
下面是文档。
datatable(
iris, extensions = 'Buttons', options = list(
dom = 'Bfrtip',
buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
)
)
推荐答案
查看此答案:按钮:带滚动条的下载按钮仅下载几行
按钮是导出所有数据还是仅显示可见数据,由 DT :: renderDT <中的
服务器
参数确定。 / code>函数调用。如果 server = FALSE
,则按钮将导出表中的所有数据,而如果 server = TRUE
,则仅导出可见数据。
Whether the buttons export all data or only visible data is determined by the server
argument in the DT::renderDT
function call. If server=FALSE
then the buttons will export all data in the table, while if server=TRUE
they will only export visible data.
您可以将 server
参数设置为变量,以使其成为可选选项。
You could set the server
argument with a variable to make this a selectable option.
output$table <- DT::renderDT(server = input$download_all, {
DT::datatable( ... )
}
您可能要查看的另一个选项是 exportOptions:修饰符:selected
选项,用于确定是仅下载选定的行(默认行)还是下载所有行。您可以在此处阅读有关该选项的信息: https://datatables.net/extensions/buttons/examples/print/select.html
The other option you might want to look at is the exportOptions: modifier: selected
option that determines whether to download only selected rows (the default) or all rows. You can read about that option here: https://datatables.net/extensions/buttons/examples/print/select.html
请注意,如果您的数据表很大,您的用户可能会使用 server = FALSE
遇到性能和内存问题。
Note that your users might run into performance and memory issues using server=FALSE
if your data table is very large.
这篇关于按钮扩展名可下载所有数据或仅下载可见数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!