Consider the following table using the reactable and reactablefmtr packages:
library(reactable)
library(reactablefmtr)
my_color_pal <- c("white", "red")
df <- head(mtcars[,"mpg", drop = FALSE])
reactable(
df,
columns = list(
mpg = colDef(style = color_scales(df, colors = my_color_pal))
)
)
I get this:
Instead of using the current range of the mpg column, I want to set the 'domain' of the color scales where values close to zero are white and values close to 100 are red.

One option would be to use e.g.
scales:: col_numericto create a palette function for your desired domain. This function could then be used to add a column of colors to your dataset which could then be used to color the table cells via thecolor_refargument ofcolor_scales:EDIT A second option to achieve the desired result would be to use a custom color scale function which following the Conditional Styling vignette could be implemented like so: