I have a short question regarding (r)handsontable. Is it possible to change cell borders using the renderer
parameter of the hot_col
function ? I tried to find something equivalent to td.style.background
, but did not find anything on Google. I've tried things like td.style.border
but it did not work...
If anyone has the answer, I would be grateful !
Thanks in advance
library(shiny)
library(rhandsontable)
ui <- fluidPage(
rHandsontableOutput('table')
)
server <- function(input, output) {
df <- data.frame(alphabet = letters[1:10],
include = TRUE,
include2 = FALSE)
output$table <- rhandsontable::renderRHandsontable({
col_highlight <- 2
rhandsontable(df, height = 500) %>%
hot_col(col_highlight,
renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.CheckboxRenderer.apply(this, arguments);
var col_value = instance.getData()[row][1]
if ( col_value ) {
td.style.background = '#C3FA9A';
}
if ( !col_value) {
td.style.background ='#ff4d4d'
}}") })}
shinyApp(ui, server)
CodePudding user response:
The CSS property is backgroundColor
:
output$table <- rhandsontable::renderRHandsontable({
col_highlight <- 2
rhandsontable(df, height = 500) %>%
hot_col(
col_highlight,
renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.CheckboxRenderer.apply(this, arguments);
var col_value = instance.getData()[row][1];
td.style.backgroundColor = col_value ? 'red': 'green';
td.style.borderStyle = 'solid';
td.style.borderWidth = col_value ? '2px' : '4px';
td.style.borderColor = col_value ? 'yellow' : 'crimson';
}"
)
})