在 R 中格式化 HTML 标题

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

我使用可反应包创建了一个表格,但我不确定如何格式化 HTML 标题,以便它们与表格共享相同的样式,例如字体、颜色和背景颜色。我希望它看起来像一个整体,而不是看起来不合适。

这是我的代码:

library(reactable)
library(htmltools)

options(reactable.theme = reactableTheme(
  color = "hsl(233, 9%, 87%)",
  backgroundColor = rgb(38/255,42/255,51/255,142/240),
  borderColor = rgb(152/255,156/255,165/255,240/240)
  ))

example<- reactable(data.frame(country=c("argentina","brazil"),
                           value=c(1,2)
))

final <- htmlwidgets::prependContent(example, 
                                      list(h2(class = "title", "title 1"),
                                           h4(class = "subtitle", "subtitle")))


print(final)

你会做什么?

r reactable
1个回答
2
投票

使用

htmltools::tags$style
创建样式标签,然后您可以编写要应用于标题的CSS

htmlwidgets::prependContent(
    final,
    htmltools::tags$style(
      "h2, h4 {color:hsl(233, 9%, 87%)"
    )
  )
© www.soinside.com 2019 - 2024. All rights reserved.