I have a dataframe of values that I'm attempting to render as a table in R Shiny. There are certain values which I want to extend to take up multiple columns in the same way in which you'd use the HTML rowspan attribute. However, if I were to do that I'd have to create the whole table from scratch, and I would much prefer to use the DT library for easy conversion from my datatable.
As an example I've created the following script:
# ui.R
fluidPage(
DT::dataTableOutput("table")
)
# server.R
library(DT)
function(input, output) {
output$table <- DT::renderDataTable({
df <- data.frame(A = c("Trial 1", 1, 1, 1), B = c("", 1, 1, 1), C = c("", 1, 1, 1),
D = c("Trial 2", 2, 2, 2), E = c("", 2, 2, 2), F = c("", 2, 2, 2),
G = c("Trial 3", 3, 3, 3), H = c("", 3, 3, 3), I = c("", 3, 3, 3))
DT::datatable(df,
options = list(dom = "t",
ordering = FALSE))
})
}
This script renders the following UI:
How can I expand out the cells containing "Trial 1", "Trial 2", and Trial 3" so that they each take up three columns?