Hide the column names in DT::datatable()
Asked Answered
C

2

9

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)
Clearwing answered 23/1, 2019 at 0:43 Comment(0)
B
7
datatable(empty, colnames = c("", ""))

EDIT

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

To make the code more robust

Beady answered 23/1, 2019 at 0:46 Comment(3)
this is cool.exactly what I needed. Do you if I can skip those up-down arrows next to the column names as well?Clearwing
datatable(empty, colnames = rep("", ncol(empty)),options=list(ordering=F))Kiser
tnx a lot great!Clearwing
C
15

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();",
              "}")
          )
)
Collide answered 23/1, 2019 at 10:42 Comment(3)
@Laurent you should definitely write a book, you're the most knowledgeable person I've seen online in regards of Shiny.Machinist
Neat. Works beautifullyOutdoor
by the way, this solution is causing a side undesired effect. The datatable it generates doesn't respect the UI column=n format. For example, on my end my table should follow the ui parameter column(10,...) but when I use the suggested code above, the table shrinks considerably.Machinist
B
7
datatable(empty, colnames = c("", ""))

EDIT

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

To make the code more robust

Beady answered 23/1, 2019 at 0:46 Comment(3)
this is cool.exactly what I needed. Do you if I can skip those up-down arrows next to the column names as well?Clearwing
datatable(empty, colnames = rep("", ncol(empty)),options=list(ordering=F))Kiser
tnx a lot great!Clearwing

© 2022 - 2024 — McMap. All rights reserved.