Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

203
Visualizações
How to change the colour of some rows with rhansontable and checkbox?

I want to change the colour of the whole row when the user unchecks a checkbox present in one of the cells. (Could be multiple rows)

So far I'm only able to change the colour of the cell containing the checkbox rather than the whole row. In this example, the whole row 6 should be coloured.

enter image description here

library(shiny)
library(rhandsontable)

# Define UI for application that draws a histogram
ui <- fluidPage(
    rHandsontableOutput('table')
)

# Define server logic required to draw a histogram
server <- function(input, output) {

    df <- data.frame(alphabet = letters[1:10],
                     include = TRUE)

    output$table <- rhandsontable::renderRHandsontable({

        rhandsontable(df, height = 500) %>%
        hot_col(col = "include",
                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 === false) {
                    
                        td.style.background = 'pink';
                    }
                }
            ")
        })
}

# Run the application
shinyApp(ui = ui, server = server)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Solved it.

library(shiny)
library(rhandsontable)

# Define UI for application that draws a histogram
ui <- fluidPage(
    rHandsontableOutput('table')
)

# Define server logic required to draw a histogram
server <- function(input, output) {

    df <- data.frame(alphabet = letters[1:10],
                     include = TRUE)

    output$table <- rhandsontable::renderRHandsontable({

        rhandsontable(df, height = 500) %>%
        hot_col(col = "include",
                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 === false) {
                    
                        td.style.background = 'pink';
                    }
                }
            ") %>%
        hot_col(col = "alphabet",
                renderer = "
                function (instance, td, row, col, prop, value, cellProperties) {
                
                    Handsontable.renderers.TextRenderer.apply(this, arguments);

                    var col_value = instance.getData()[row][1]

                    if (col_value === false) {
                    
                        td.style.background = 'pink';
                    }
                }
            ")
        })
}

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda