类似于此问题:Shiny: Merge cells in DT::datatable
我想知道是否有一种方法可以合并两个或多个列。在下面的示例中,仅合并了第1列中的重复行,如果我还想合并每个部分中第5列中的重复行,该怎么办。例如,在表的图像中,我希望合并Petal.Width中的0.2,以及Petal.Width中1.5的。有可能吗?
library(shiny)
library(DT)
dat <- iris[c(1,2,3,51,52,53,101,102,103), c(5,1,2,3,4)]
ui <- fluidPage(
DTOutput("table")
)
server <- function(input, output){
output[["table"]] <- renderDT({
dtable <- datatable(dat, rownames = FALSE,
options = list(
rowsGroup = list(0) # merge cells of column 1
))
path <- "U:/Data/shiny/DT/www" # folder containing dataTables.rowsGroup.js
dep <- htmltools::htmlDependency(
"RowsGroup", "2.0.0",
path, script = "dataTables.rowsGroup.js")
dtable$dependencies <- c(dtable$dependencies, list(dep))
dtable
})
}
shinyApp(ui, server)
您要做的就是使用您链接的答案(使用datatables-rowsgroup插件),并指定多余的列以合并重复的结果:
dtable <- datatable(dat, rownames = FALSE,
options = list(
rowsGroup = list(0,4) # merge cells of column 1 and 5
))