r语言 - DT 表也下载隐藏列



有没有办法排除隐藏在 DTtable 中的下载列。例

columnDefs = list(list(visible=FALSE, targets=c(14))

从上面的代码中,第 14 列被隐藏。但是如果我在 excel 中下载表格,它也会下载此列。我们可以排除这一点吗?

目前下载

如下
DT::datatable(df,
escape = FALSE, rownames = FALSE,selection = 'single',
extensions = c('Buttons'),
options = list(
scrollX = TRUE,
paging = TRUE,
buttons = c('excel'),
columnDefs = list(list(visible=FALSE, targets=c(2))),                                     
pageLength = 400, sScrollY = '40vh',
autoWidth = FALSE,
buttons = list('copy', 'print',
list(
extend = 'collection',
buttons = c('csv', 'excel'),
text = 'Download'
))
)
)

你可以做

buttons = list(
list(extend = "excel", exportOptions = list(columns = visibleCols))
)

其中visibleCols是包含要下载的列的索引的向量。

最新更新