13

I have a datatable in R Shiny and would like to have headers that span multiple columns like below:

enter image description here

How can this be achieved in R Shiny?

Gavin Simpson
  • 164,190
  • 25
  • 377
  • 440
mchen
  • 9,289
  • 12
  • 68
  • 118

2 Answers2

14

Theres already example http://rstudio.github.io/DT/

library(DT)
sketch = htmltools::withTags(table(
  class = 'display',
  thead(
    tr(
      th(rowspan = 2, 'Species'),
      th(colspan = 2, 'Sepal'),
      th(colspan = 2, 'Petal')
    ),
    tr(
      lapply(rep(c('Length', 'Width'), 2), th)
    )
  )
))
datatable(iris[1:20, c(5, 1:4)], container = sketch, rownames = FALSE)

enter image description here

Pork Chop
  • 26,081
  • 5
  • 59
  • 70
2

Have a look at new package from RStudio DT (https://github.com/rstudio/DT)? Here http://rstudio.github.io/DT/ you could find an example of what you need.

kismsu
  • 1,009
  • 7
  • 20