rhtmlwidgetsreactable

How to Change the Font Used in htmlwidgets for R?


I have a table that I am building using reactable in R, and want to add a title with the same font I am using in the table itself. I figured out how to add a title, but how do I change the font?

library(htmlwidgets)
library(reactable)

reactable(head(iris, 10),
          style = list(fontFamily = 'Menlo',
                       fontSize = '14px'),
          highlight = TRUE) %>%
  htmlwidgets::prependContent(htmltools::tags$h1("This is my Title"))

Solution

  • You can set the style when you add the tag. Right clicking on the column titles show that they are using font-family: Menlo (the result of you asking for fontFamily = 'Menlo'), so this gives you the same font:

    reactable(head(iris, 10),
           style = list(fontFamily = 'Menlo',
                        fontSize = '14px'),
           highlight = TRUE) %>%
    htmlwidgets::prependContent(htmltools::tags$h1("This is my Title", 
                                                   style = "font-family: Menlo"))
    

    You would use style = "font-family: Menlo; font-size: 14px" to match the size as well.