R DT 基于行配置容器

Pra*_*kar 6 r shiny dt

我正在尝试使用 DT 创建一个表,并且我想创建一个显示数据的容器,如下所示。桌子

但是,我最接近的是下面的代码。

library(data.table)
library(DT)

#a custom table container
sketch = htmltools::withTags(table(
  class = 'display',
  thead(
    tr(
      th(colspan = 3, 'First'),
      th(colspan = 8, 'Criteria')
    ),
    tr(
      th(colspan = 3, 'Name1'),
      th(colspan = 1, 'Car'),
      th(colspan = 3, 'Criteria'),
      th(colspan = 2, 'Criteria2'),
      th(colspan = 3, 'Criteria3')
      ),
    tr(
      lapply(c('vs', 'gear', 'carb', 'Car', 'mpg', 'cyl', 'disp', 'hp', 'drat', 'wt', 'qsec', 'am'), th)
    )

  )
))


mtcars$Car = row.names(mtcars)
header_trial = mtcars
header_trial = data.table(header_trial)
setkey(header_trial, vs, gear, carb)
setcolorder(header_trial, c('vs', 'gear', 'carb', 'Car', 'mpg', 'cyl', 'disp', 'hp', 'drat', 'wt', 'qsec', 'am'))
datatable(header_trial, container = sketch, rownames = FALSE, class = "cell-border stripe")
Run Code Online (Sandbox Code Playgroud)

你能帮我在容器中配置表格的行,以便像图片中的例子一样显示吗?

谢谢!