【问题标题】:Shiny merge cells in DT::table on two or more columns两列或多列上 DT::table 中的闪亮合并单元格
【发布时间】:2020-04-12 08:54:38
【问题描述】:

与这个问题类似: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)

【问题讨论】:

    标签: javascript shiny dt


    【解决方案1】:

    您需要做的就是使用您链接的答案(使用 datatables-rowsgroup 插件)并指定额外的列以合并重复的结果:

    dtable <- datatable(
        dat,
        rownames = FALSE, 
        options = list(
           rowsGroup = list(0,4))) # merge cells of column 1 and 5
    

    【讨论】:

    • 哦,谢谢!不知道 rowsGroup 需要什么,也没有意识到它从 0 开始索引。
    猜你喜欢
    • 2019-07-28
    • 2016-01-02
    • 2019-12-04
    • 2020-11-14
    • 2021-10-02
    • 2021-10-16
    • 2019-03-12
    • 2017-01-21
    相关资源
    最近更新 更多