簡體   English   中英

閃亮:合並 DT::datatable 中的單元格

[英]Shiny: Merge cells in DT::datatable

我想在閃亮的 DT::datatable 中合並列中的幾行。 有可能這樣做嗎?

目前我能夠輸出如下所示:

在此處輸入圖片說明

但理想情況下,我想合並行並希望輸出如下內容:

在此處輸入圖片說明

是否可以在 DT::datatable 中合並這樣的行?

datatables-rowsgroup 庫的幫助下是可能的。 下面是一個例子:

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)

在此處輸入圖片說明

嘿,據我所知,在 DT 中不可能做到這一點,我有另一種方法來實現它。

 kable(c, align = "c") %>%
  kable_styling(bootstrap_options = "striped", full_width = F, position = "left",font_size = 12)%>%
  column_spec(1, bold = T) %>%
  collapse_rows(columns = 1, valign = "middle")

請嘗試一下,它有效:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM