How to create datatable with complex header in R Shiny?

我只是一个虾纸丫 提交于 2020-08-16 07:57:08

问题


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?


回答1:


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)




回答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.




回答3:


I hope it could be useful.

library(shiny)
library(DT)

ui <- navbarPage(
 title = "Iris DataTable",
 tabPanel('Display length', dataTableOutput("table"))
 )

server <- function(input, output) {
 output$table <- renderDataTable(
 datatable(iris, options = list(pageLength = 25))
 )
}

shinyApp(ui, server)


来源:https://stackoverflow.com/questions/22897852/how-to-create-datatable-with-complex-header-in-r-shiny

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!