dat <- iris[1:5,1:5]
colours2apply <- sample(x=c(rgb(1, 0, 0 ), rgb(1, 1, 0 ), rgb(0, 1, 1 )), 25, replace = T) %>%
matrix(nrow=5) %>%
data.frame()
dat <- cbind(dat, colours2apply)
datatable(dat,
options = list(columnDefs = list(list(visible=FALSE, targets = 6:10)))) %>%
formatStyle(1, valueColumns = 6, backgroundColor = JS("value")) %>%
formatStyle(2, valueColumns = 7, backgroundColor = JS("value")) %>%
formatStyle(3, valueColumns = 8, backgroundColor = JS("value")) %>%
formatStyle(4, valueColumns = 9, backgroundColor = JS("value")) %>%
formatStyle(5, valueColumns = 10, backgroundColor = JS("value"))
![enter image description here](https://i.stack.imgur.com/OG6OI.png)
Или, используя цикл:
DT <- datatable(dat,
options = list(columnDefs = list(list(visible=FALSE, targets = 6:10))))
for(i in 1:5){
DT <- DT %>%
formatStyle(i, valueColumns = i+5, backgroundColor = JS("value"))
}
DT