1

I have to create a reactable in R and insert a warning icon in specific rows (rows where the value is > 0). let's do it using the example of iris table : I want to insert a warning icon in rows with Petal.width <0.2

data <- data('iris')
table <- reactable(iris,searchable = TRUE,sortable = TRUE,pagination=FALSE,bordered =TRUE,highlight = TRUE,showSortIcon = TRUE,
                            columns= list(Petal.Width = colDef(name =  'Petal.Width', align = 'center',
                                            cell = icon_sets(iris, icon_size = 25, 
                                             icons ="warning", 
                                            colors = c("red") , icon_position = "left")))
)

How to modify this code to have the icons in only the rows with Petal.Width <0.2

thank you for helping

1 Answers1

1

You could use shiny::icons() conditionally, e.g.

library(reactable)
library(reactablefmtr)

reactable(iris,searchable = TRUE,sortable = TRUE,pagination=FALSE,bordered =TRUE,highlight = TRUE,showSortIcon = TRUE,
                   columns= list(Petal.Width = colDef(name =  'Petal.Width', align = 'center',
                cell = function(value) {
                  if (value  < 0.2 )  shiny::icon("warning", class = "fas",  
                    style = "color: orange") else value
                    }
                   )))

enter image description here

Julian
  • 6,586
  • 2
  • 9
  • 33