I would like to combine reactable
's groupBy aggregates with the ability to show information from other cells. For example, I can show/combine information from other columns like so:
library(reactable)
library(dplyr)
library(htmltools)
data <- starwars %>%
select(character = name, height, mass, gender, homeworld, species)
reactable(
data,
columns = list(
character = colDef(
# Show species under character names
cell = function(value, index) {
species <- data$species[index]
species <- if (!is.na(species)) species else "Unknown"
div(
div(style = "font-weight: 600", value),
div(style = "font-size: 0.75rem", species)
)
}
),
species = colDef(show = FALSE)
),
defaultPageSize = 6
)
Independently, I can use the groupBy
argument to aggregate rows:
reactable(
data,
groupBy = c("character"),
defaultPageSize = 6
)
But when attempting to combine the two, things do not work as expected:
reactable(
data,
groupBy = c("character"),
columns = list(
character = colDef(
# Show species under character names
cell = function(value, index) {
species <- data$species[index]
species <- if (!is.na(species)) species else "Unknown"
div(
div(style = "font-weight: 600", value),
div(style = "font-size: 0.75rem", species)
)
}
),
species = colDef(show = FALSE)
),
defaultPageSize = 6
)
There is a grouped
argument within the colDef()
function that I think holds the answer, but I have not been able to get this to work.
Here are some links that could be helpful: