闪亮:合并 DT::datatable 中的单元格
Shiny: Merge cells in DT::datatable
我想在闪亮的 DT::datatable 中的列中合并几行。可以这样做吗?
目前我能够输出如下所示:
但理想情况下我想合并行并输出如下内容:
是否可以在 DT::datatable 中像这样合并行?
嘿,据我所知,在 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")
请尝试一下,它有效:)
在 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)
我想在闪亮的 DT::datatable 中的列中合并几行。可以这样做吗?
目前我能够输出如下所示:
但理想情况下我想合并行并输出如下内容:
是否可以在 DT::datatable 中像这样合并行?
嘿,据我所知,在 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")
请尝试一下,它有效:)
在 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)