Мы можем увидеть это решение здесь rhandsontable - Custom Renderer , однако, это решение имеет проблему, когда мы реализуем в блестящем, к счастью, проблема была решена здесь
library(shiny)
library(tidyverse)
library(rhandsontable)
# basic user interface (not important here)
ui <- fluidPage(
rHandsontableOutput(outputId = "ex")
)
# server side calculations
server <- function(input, output, session) {
# create the rhandsontable object and define conditional formatting
output$ex = renderRHandsontable({
# 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 index with columns sum is equal to 1
col_highlight <- unname(which(colSums(ex_data[c(2,3)])==1))
rhandsontable(ex_data, col_highlight = col_highlight,
width = 550, height = 300) %>%
hot_cols(renderer = "
function(instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.NumericRenderer.apply(this, arguments);
if (instance.params) {
hcols = instance.params.col_highlight;
hcols = hcols instanceof Array ? hcols : [hcols];
}
if (instance.params && hcols.includes(col)) {
td.style.background = 'lightgreen';
}
}")
})
}
shinyApp(ui,server)
![enter image description here](https://i.stack.imgur.com/nBdlJ.png)