I have the following code so far as an example:
library(DT)
datatable(iris, options = list(pageLength = 5)) %>%
formatStyle(
'Sepal.Width',
backgroundColor = styleInterval(3, c('gray', 'yellow'))
)
I am interested though in highlighting only a specific "cell" based on a condition.
For example if iris[3, 2] > 3.1
then background colour should be yellow.
for reference http://rstudio.github.io/DT/
sessionInfo()
DT_0.1
You can do this with the DT Helper Functions. There is a function to style the cells for certain intervals (
styleInterval()
) or if the cell value is equal to something with (styleEqual()
). It doesn't seem thatstyleEqual()
supports the direct input of a condition, but you could calculate the condition first (maybe make another column for it) and use it then.As described on the page linked above (under section 2 "Style Table Cells") you can do it for example like this: