I have a dataset that let's say has two columns. One column is for score and the other is for the actual value. I would like to colour the actual value column based on the score column, then remove the score column. I already did this but I can not remove the score column using datatable options. Remember, by datatable I mean DT::datatable()
the interactive interface one.
## Sample df ##
df = data.frame(
actual = sample(1:10),
score = runif(10)
)
----------
## Coloring breaks ##
brks <- quantile(df, probs = seq(.05, .95, .05), na.rm = TRUE)
clrs <- round(seq(255, 40, length.out = length(brks) + 1), 0) %>%
{paste0("rgb(255,", ., ",", ., ")")}
----------
## Generating DT ##
datatable(df) %>% formatStyle(
'actual', 'score',
backgroundColor = styleInterval(brks, clrs))
More information here about styling:
Not applicable workaround
You can select columns first prior generating a datatable. i.e df %>% select(actual) %>% datatable(.)
but that does not work in my case because I have to do the styling first.
Expected workaround
I'd like an option to specify which columns to select using DT::datatable()
(the value column only here in this case), multiple columns in my real case.
datatable(df)
There is an options called selected
but it says it works for shiny.
I have read about options and there is a select.item
that might work, but I might be missing the correct syntax.