0

Data

df <- tibble(
  x = rep(paste0( "del", 1:10 ), 100),
  y = rep(paste0( "topic", 1:5 ), 200),
  z = paste0("question", 1:1000),
  w = 1:1000
)

Code

reactable(
  df,
  groupBy = c("x", "y"),
  columns = list(
    w = colDef(
      aggregate = "mean",
      style = JS(
        "function(rowInfo) {
        var value = rowInfo.row.extra
        if (value > 500) {
          var color = '#008000'
        } else {
          var color = '#e00000'
        }
        return { color: color, fontFamily: 'monospace' }
      }")
    )
  )
)

Question

For some reason, the JS code if (value > 500) is not evaluating to TRUE when the value is indeed bigger than 500. Am i missing something? Why is that and how do i fix?

1 Answers1

0

In using datatables (presumably using a similar javascript call) I used this snippet wrapped in JS()

"
 value <= 10 ? 'green' : (value <= 15 ? 'yellow' : (value >= 15 ? 'red' : 'white'))
"

If a value is less than 10 its green, between 10 and 15 its yellow and greater than 15 its red.

Could a similar syntax be what you need?

"
value>500 ? '#008000' : 'e00000'
"