Reactable Lib - Conditional formatting(background cell) multiple columns

I've a dataframe with 30 columns. But from 4 to 30th columns I have to apply a condition. If the value is equal to 1 or more then the background cell change to Red(lightCoral). I did it, For the moment I apply the change on all the columns concerned and it works. It makes a lot of codes. I need a good way to simplify my codes.

ds_color=NULL
reactable(tab_jan2021, filterable = TRUE, minRows = 100,defaultPageSize = 100,columns = list(
  SORTIE= colDef(cell = function(value) {
    # Render as an X mark or check mark
    if (value == 0) "\u274c No" else "\u2714\ufe0f Yes"
  }),
  ID = colDef(
       style = list(position = "sticky", left = 0, background = "#fff", zIndex = 1),
       headerStyle = list(position = "sticky", left = 0, background = "#fff", zIndex = 1)
    ),
  FAIBLESSE = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  FATIGUE = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  MAUX_DE_TETE = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  ANOREXIE = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  MAL_DE_GORGE = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  NAUSEE = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  DOUL_THORA = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  DIFF_RESPI = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  DIFF_A_AVALER = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  DOUL_ABDO = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  DIARRHEE = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  VOMISSEMENT = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  TROUBLE_DE_SOMMEIL = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  ENGOURDISSEMENT = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  SUEUR_FROIDE = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  STRESS = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  PERTE_EQUILIBRE = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  OSTEO_ARTICULAIRE = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  ),
  DOUL_MUSCULAIRE = colDef(
    style = function(value) {
    if (value > 0) {
      ds_color <- "lightCoral"
    } 
    list(background = ds_color)
  }
  )
),defaultColDef = colDef(minWidth = 155),resizable = TRUE,wrap = FALSE,)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.