Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
Changing cell color of R shiny data table dependent on its value

I am trying to color cells that meet certain conditions. For example, I would like to color cells whose value is equal to its respective column values of the first row of the data. I figured how to color specific values using javascript but can't figure out how to set the conditions as what I want. Here's the code:

library(DT)
df <- head(iris)
df %>% 
  datatable %>% 
  formatStyle(1:2, color = JS("value % 1 === 0 ? 'red' : ''"))

In this table, the highlighted cells are the ones whose values match the value of the column of the first row of the data. I would like to set javascript conditions as such that it will highlight the cells as shown in the image.

example

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you use styleEqual function, it almost work except that it underlines also the reference row :

library(DT)
df <- head(iris)
ref <- df[1,]
color <- "orange"
datatable(df) %>% 
    formatStyle(1:5,
                backgroundColor = styleEqual(ref[1:5], rep(color, 5)))
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda