【问题标题】:DT table downloads hidden column as wellDT 表也下载隐藏列
【发布时间】:2020-06-22 12:22:33
【问题描述】:

有没有办法排除在闪亮的 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'
                                     ))
                    )
      )

【问题讨论】:

  • 为什么不直接删除这个 DTtable 的输入数据框中的列?
  • 没有。需要该列,因为基于该列会生成其他列值
  • 您目前如何下载数据?发布完整的代码会有所帮助。
  • 在我的问题中编辑

标签: r shiny dt


【解决方案1】:

你可以的

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

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

【讨论】:

  • 谢谢。我试过这条线。但是现在数据本身并没有显示出来:)
  • 我试过buttons = list( list(extend = c("excel", exportOptions = list(columns = c(2,3))) ))
  • 你能帮帮我吗?
猜你喜欢
  • 2019-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-23
相关资源
最近更新 更多