View source: R/kableHighlightColumns.R
kableHighlightColumns | R Documentation |
Basic highlighting of each cell in a table based on a binary condition. Note that this uses cell_spec, which is deprecated in favor of column_spec, but I haven't figured out how to achieve this is column_spec yet.
kableHighlightColumns(
data_dt,
cols_v,
condition_v,
bgColor_v = c("white", "red"),
tColor_v = c("black", "white"),
...
)
data_dt |
data.table to color columns of |
cols_v |
vector of column names to highlight cells of |
condition_v |
character string of condition to determine cell color. See details |
bgColor_v |
vector of length two containing color values to color cell backgrounds with |
tColor_v |
vector of length two containing color values to color cell text with |
Condition will be fed into an ifelse statement and each column provided in cols_v will be checked against it. For example, condition_v = "> 5" will be evaluated such that background = ifelse(data_dt[[col_v[i]]] > 5, bgColor_v[1], bgColor_v[2]), where i is the index of the current column. (And the same for text color).
Output a kable with "standard" formatting updated with highlighted cells as defined in arguments.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.