I'm trying to combine the following two reactable features in R:
- Conditional styling
- Aggregating / grouping
My goal is to highlight the aggregated (sum) group headers with different shades of orange, depending on the group sum value. This way, it's easier to spot groups with high/low values.
I use only one color range c("#ffe4cc", "#ffb54d")
for both cell values and group headers, e.g. 100
as cell value and 100
as group header result in the same color.
What I've tried so far (this is a simplified example, my real world problem needs highlighting over multiple columns/groups):
library(datasets)
library(reactable)
data('CO2')
get_orange <- function(x) rgb(colorRamp(c("#ffe4cc", "#ffb54d"))(x), maxColorValue = 255)
reactable(
CO2,
groupBy = c('Plant', 'Type', 'Treatment'),
columns = list(
conc = colDef(
aggregate = 'mean'
),
uptake = colDef(
aggregate = 'sum',
style = function(value) {
normalized <- (value - min(CO2$uptake)) / (max(CO2$uptake) - min(CO2$uptake))
color <- get_orange(normalized)
list(background = color)
}
)
)
)
Resulting in: Screenshot expected vs actual
> packageVersion('reactable')
[1] ‘0.2.3’