I have successfully generated a dataset where I assigned color codes to a column based on values from another column.
colourCount = length(unique(Desc.File$VARIABLECODE))
getPalette = colorRampPalette(brewer.pal(9, "Set1"))
Colors <- getPalette(colourCount)
Desc.File$ColorCode <- factor(Desc.File$VARIABLECODE, labels = Colors)
The result is a list of HEX color codes:
"#E41A1C" "#D42229" "#C52B37" "#B63445" "#A73D52" "#974560" "#884E6E" "#79577C" "#6A6089" "#5B6997" "#4B71A5" "#3C7AB2" "#3880B1" "#3A85A8" "#3C899E" "#3E8D94" "#3F918B" "#419681" "#439A77" "#459E6E" "#47A364" "#49A75A"
My goal now is to utilize these colors in a plot and also apply them as the background/text color in Rhandsontable.
color_renderer = "function(instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
clr = instance.params.ColorCode
td.style.background= hex(clr[row])
}
"
colnames(Summary.tab) <- c("Code", "Brand", "Type", "Description", "Metric", "ColorCode", "Execution", "Cost")
Summary.tab <- data.frame(Check=rep(TRUE, n),Summary.tab)
DT = rhandsontable(Summary.tab, readOnly = FALSE, rowHeaders= NULL, useTypes= TRUE, selectCallback = TRUE) %>% hot_col("Code", renderer=color_renderer)
I am attempting to use the renderer to extract colors from the color column in the dataset and assign them as the background color, however, it does not seem to be functioning as expected. (I am new to JavaScript coding so I might be missing something)
Please provide assistance :)