View source: R/dt_format_col.R
| dt_fmt_col | R Documentation |
Colours DT columns based on the minimum and maximum of each column. Defaults to a purple-green colour scheme HULK which is colourblind-friendly, and naturally associates "green" to "good" and "purple" to "bad".
dt_fmt_col(
dt,
columns,
column_range = NULL,
colours = c("#9162C5", "#F1F1F1", "#6BA359"),
reverse_colours = FALSE,
colour_steps = 100
)
dt |
a DT object created by |
columns |
a character or numeric vector of column identifiers (column names or indices) |
column_range |
numeric or "auto": either the minimum and maximum range to be coloured, or "auto" which defaults to the max and min of the table column. |
colours |
A set of hex colours to be passed on to |
reverse_colours |
logical: reverses direction of colour scale |
colour_steps |
number: how many distinct colours to create, default 100 |
A DT object with added colour formatting
DT::datatable(mtcars) |>
# standard: formats high values as green, low values as purple
dt_fmt_col(columns = c("hp", "cyl")) |>
# reverse: formats low values as green, high values as purple
dt_fmt_col(columns = "mpg", reverse_colours = TRUE) |>
# custom colours
dt_fmt_col(columns = "wt", colours = c("orange", "white", "blue"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.