为使用reactable创建的表格添加标题

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

我创建了一个包含可反应包的表,但我不确定如何为其添加标题。 我在 Github 上有几个例子,他们添加了一个,但我无法达到相同的结果。 这是我的代码:

library(reactable)
library(htmltools)
example<- reactable(data.frame(country=c("argentina","brazil"),
                     value=c(1,2)
                     ))
div(class = "table",
    div(class = "title", "Top CRAN Packages of 2019"),
    example
)
print(example)

这是一个示例,他们将标题添加到表格中,其中我曾经尝试添加我的标题:

https://glin.github.io/reactable/articles/twitter-followers/twitter-followers.html

r reactable
1个回答
4
投票

reactable
函数返回一个特殊的对象,该对象恰好使用
htmlwidgets
包来帮助渲染。您可以使用
htmlwidgets::prependContent
函数将 HTML 内容添加到标头的对象中。例如

withtitle <- htmlwidgets::prependContent(example, 
    h2(class = "title", "Top CRAN Packages of 2019"))

print(withtitle)

这会在打印时将

<h2>
标题标签和内容放置在表格元素之前。

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