Display datatable in colorful manner based on the data

Hi Shiny experts,

Is it possible to display the table in data table in a colorful way ?
If the difference between the subsequent column is positive : Green color row
If the difference between the subsequent column is negative: Red color row
If there is no difference, then white (default) color

Reference for code:
https://shiny.rstudio.com/articles/datatables.html

hi, you might have a look at that https://rstudio.github.io/DT/

here is a piece of code (sorry if it's messy...), there is probably other way to achieve that!

iris_df <- iris %>% 
mutate(
  diff = cut(Sepal.Width - Petal.Length, breaks = c(-Inf, 0, +Inf))
) 

datatable(iris_df) %>% 
  formatStyle('diff',
    backgroundColor = styleEqual(levels(iris_df$diff), c('green', 'red'))
  ) 

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