Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide the column names in DT::datatable()

Tags:

r

dt

Is there any way to hide the column names when using the DT::datatable()

That returns now data at all:

empty<-data.frame(c("a","d","d"),c("s","d","d"))
library(DT)
datatable(empty,colnames = F)
like image 476
firmo23 Avatar asked Dec 11 '22 04:12

firmo23


2 Answers

Instead of setting blank column names, you can completely remove the header in this way:

library(DT)

datatable(head(iris), 
          options = list(
            headerCallback = JS(
              "function(thead, data, start, end, display){",
              "  $(thead).remove();",
              "}")
          )
)
like image 64
Stéphane Laurent Avatar answered Jan 03 '23 20:01

Stéphane Laurent


datatable(empty, colnames = c("", ""))

EDIT

datatable(empty, colnames = rep("", ncol(empty)))

To make the code more robust

like image 21
astrofunkswag Avatar answered Jan 03 '23 22:01

astrofunkswag