2

Columns in reactable (R package reactable) can be styled with a list of styles, a function or javascript - which works if I want to use one way only. How can these be combined (without rewriting the list, function or javascript code?

Example:

library(reactable)

list_style <- list(background = "#eee")

js_style <- JS("
    function(rowInfo) {
      return {fontWeight: 'bold' }
    }
  ")

fn_style <- function(value) {
    color <- "#008000"
    list(color = color)
}

df <- data.frame(x = 1:10, y = 11:20)

reactable(
  df,
  columns = list(
    x = colDef(
      style = c(list_style, js_style, fn_style) # This generates the below error
    )
  )
)

Error:

Error in colDef(style = c(list_style, js_style, fn_style)) : 
  `style` must be a named list, character string, JS function, or R function
Vlad
  • 3,058
  • 4
  • 25
  • 53
  • Since this so package specific, it's probably a better question for the github site for that package: https://github.com/glin/reactable/issues. It doesn't appear to accept multiple types so you're really making a feature request. Since it can accept a function, you could write your own function to combine different styles, but combing JS and non-JS code will probably be tricky. – MrFlick Jul 09 '20 at 02:27

1 Answers1

0
reactable(
  df,
  columns = list(
    x = colDef(
      style = list(list_style, js_style, fn_style)
    )
  )
)

it seems that your style out of list, please replace those code with this reactable

  • While this code snippet may be the solution, including a detailed explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Shawn Hemelstrand Jan 31 '23 at 14:34