我想以 Shiny 的方式合并 DT::datatable 列中的几行。可以这样做吗?
目前我能够输出如下所示:
但理想情况下,我想合并行并希望输出如下所示的内容:
是否可以在 DT::datatable 中合并这样的行?
最佳答案
在 datatables-rowsgroup library 的帮助下这是可能的。这是一个例子:
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)
关于r - Shiny:合并 DT::datatable 中的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39484118/