I opened a thread about how to add range bars in a datatable here:Programmatically color format numeric columns in a datatable.
However instead of fitting the ranges based on the whole data frame, I would like to format based on the range of each individual column. I figured out some code that works, however, it is most definitely daunting and not programmatic.
library(magrittr)
library(DT)
# Specify numeric columns
foo <- sapply(iris, is.numeric)
datatable(iris, filter = 'top', options = list(pageLength = 5, autoWidth = TRUE)) %>%
formatStyle(names(iris)[foo][1],
background = styleColorBar(range(iris[, 1]), 'lightblue'),
backgroundSize = '98% 88%',
backgroundRepeat = 'no-repeat',
backgroundPosition = 'center') %>%
formatStyle(names(iris)[foo][2],
background = styleColorBar(range(iris[, 2]), 'green'),
backgroundSize = '98% 88%',
backgroundRepeat = 'no-repeat',
backgroundPosition = 'center')