I am attempting to change the cell color of cells of an R Shiny data table dependent on their value. As an example, I\'ve created the following app:
# ui.R
This page has a bunch of tips for formatting DT data tables: https://rstudio.github.io/DT/010-style.html
For your specific question, there's the function formatStyle that allows you to set aesthetics based on specific values in the table:
library(DT)
options(DT.options = list(pageLength = 5))
df = as.data.frame(cbind(matrix(round(rnorm(50), 3), 10), sample(0:1, 10, TRUE)))
# style V6 based on values of V6
datatable(df) %>% formatStyle(
'V6',
backgroundColor = styleEqual(c(0, 1), c('gray', 'yellow'))
)
# style V1 based on values of V6
datatable(df) %>% formatStyle(
'V1', 'V6',
backgroundColor = styleEqual(c(0, 1), c('gray', 'yellow'))
)