I am trying to make a reactable
with the following (I succeeded making the first but not 2 and 3):
5
or below 0.1
, color that cell red
.1
or 0
: 1
if all four columns in a certain row are all white
and 0
otherwise. For instance, since the 7th row does not have any red cells, the value will be 1.
library(tidyverse)
library(reactable)
reactable(
iris,
columns = set_names(x = colnames(iris)) %>%
map(~ {
colDef(
style = function(value) {
ds_color <- ifelse(value > 5 | value <= 0.2, "red", "white")
list(background = ds_color)
}
)
})
)
We may use if_all/if_any
library(dplyr)
iris %>%
mutate(color_ind = case_when(if_any(where(is.numeric), ~
.x > 5|.x < 1)~ "red",TRUE ~ "white"),
cnt_col = rowSums(across(Sepal.Length:Petal.Width,
~ .x > 5|.x < 1), na.rm = TRUE),
binary_white = +(!cnt_col))