I have an rhandsontable inside a shiny app. My goal is to color all cells in a column based on the sum of the column. Ex : if the sum of the values in the column is 1, then, all cells in this column are colored in green.
The expected outcome displayed to the user is like this:
It seems possible to do so with a JS formatting like this :
rhandsontable(myrhandsontable) %>%
hot_cols(renderer ="some JS script")
I have never done any JS before and I struggle to get the sum of the column inside the "some JS script
" part.
Here is a minimal reproductible exemple to work with:
library(shiny)
library(rhandsontable)
library(tidyverse)
# basic user interface (not important here)
ui <- fluidPage(
rHandsontableOutput(outputId = "ex")
)
# server side calculations
server <- function(input, output) {
# create a dummy dataset
ex_data = data.frame(id = letters[1:3],
attr1 = c(0.5, 0.4, 0.3),
attr2 = c(0.6, 0.3, 0.1))
# create the rhandsontable object and define conditional formatting
output$ex = renderRHandsontable({
rhandsontable(ex_data) # %>% renderer ="JS script for conditional formatting")
})
I unsuccessfully tried to use these posts and tutorials:
- rhandsontable change background of specific row
- Rhandsontable conditional formatting- How to highlight rows based on specific attribute value?
- https://jrowen.github.io/rhandsontable/#custom_renderer_using_r
- https://jrowen.github.io/rhandsontable/#conditional_formatting
Any idea is welcome :)