Опция с использованием JavaScript:
library(DT)
js <- c(
"function(settings) {",
" var table = settings.oInstance.api();",
" var nrows = table.rows().count();",
" for(var i=0; i<nrows; i++){",
" var vs = table.cell(i,8);",
" var cyl = table.cell(i,2);",
" if(vs.data() == 1){",
" cyl.node().style.backgroundColor = cyl.data() >= 6 ? 'green' : 'yellow';",
" }",
" }",
"}")
datatable(mtcars,
options = list(initComplete = JS(js))
)
Другая опция:
dat <- mtcars
dat$colors <- with(dat, ifelse(vs==1, ifelse(cyl>=6, "green", "yellow"), "white"))
datatable(dat,
options = list(
columnDefs = list(
list(visible = FALSE, targets = 12)
)
)
) %>% formatStyle("cyl", valueColumns = "colors", backgroundColor = JS("value"))