8

我正在尝试删除闪亮数据表中的标题行,有谁知道是否有这样做的选项?

最小的例子:

#SERVER.R
output$myTable <- renderDataTable({
  datatable(dataset, rownames = FALSE, selection = 'none', options = list(dom = 't'))
})

#UI.R
dataTableOutput('myTable')
4

3 回答 3

9

只需添加colnames = NULL到您的datatable()

datatable(mtcars, rownames = FALSE,colnames=NULL, selection = 'none', options = list(dom = 't'))

?datatable

于 2015-10-28T16:46:53.493 回答
1

塞巴斯蒂安在 15 年 10 月 28 日的回答对我来说不起作用renderDataTable(datatable(...))。使用colnames = NULLinsidedatatable(...)删除了表中的所有数据。我不得不使用colnames = ""删除表头。

于 2020-03-12T06:30:31.367 回答
1

Adding colnames = NULL no longer works and it renders an empty table. You can use headerCallBack option to add a css that hides the header row to achieve this.

headerCallback <- c(
  "function(thead, data, start, end, display){",
  "  $('th', thead).css('display', 'none');",
  "}"
)

datatable(mtcars, 
          rownames = FALSE,
          colnames=NULL, 
          selection = 'none', 
          options = list(
            dom = 't',
            headerCallback = JS(headerCallback)
          )
)

于 2020-08-25T10:30:49.403 回答