I have a datatable inside an R shiny app and I'm trying to do what is illustrated in the following manual: https://rstudio.github.io/DT/010-style.html -> Style a full table. However, I'm trying to customize the colors of only columns 2 and 3 in this example.
My code is the following:
datatable(df,
filter = 'none',
rownames= FALSE,
caption = paste0("Execution Alpha by sector."),
options = list(scrollX = F
#,dom = 'ft'
, lengthChange = T
, pagingType = "numbers" # this hides the Next and Previous buttons --> https://datatables.net/reference/option/pagingType
, autoWidth = T
,pageLength = 20 # this determines how many rows we want to see per page
, info = FALSE # this will hide the "Showing 1 of 2..." at the bottom of the table --> https://stackoverflow.com/questions/51730816/remove-showing-1-to-n-of-n-entries-shiny-dt
,searching = FALSE # this removes the search box -> https://stackoverflow.com/questions/35624413/remove-search-option-but-leave-search-columns-option
)) %>%
formatStyle(
colnames(df)[2:3],
background = styleColorBar(df[,2:3], 'lightblue'),
backgroundSize = '100% 80%',
backgroundRepeat = 'no-repeat',
backgroundPosition = 'left' # center
)
I get an error saying: "only defined on a data frame with all numeric variables" however all the values in columns 2 and 3 are numbers. Any suggestions? Thanks