如何更改 R 的 htmlwidgets 中使用的字体?

问题描述 投票:0回答:1

我有一个正在 R 中使用 Reactable 构建的表格,并且想要添加一个与我在表格本身中使用的字体相同的标题。我知道如何添加标题,但如何更改字体?

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"))
r htmlwidgets reactable
1个回答
4
投票

添加标签时可以设置样式。 右键单击列标题显示他们正在使用

font-family: Menlo
(您要求
fontFamily = 'Menlo'
的结果),因此这将为您提供相同的字体:

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"))

您也可以使用

style = "font-family: Menlo; font-size: 14px"
来匹配尺寸。

© www.soinside.com 2019 - 2024. All rights reserved.