r - 为使用 reactable 创建的表添加标题
问题描述
我创建了一个包含可反应包的表,但我不确定如何为其添加标题。我在 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
解决方案
该reactable
函数返回一个特殊对象,该对象恰好使用htmlwidgets
包来帮助渲染。您可以使用该htmlwidgets::prependContent
函数将 HTML 内容添加到标题的对象中。例如
withtitle <- htmlwidgets::prependContent(example,
h2(class = "title", "Top CRAN Packages of 2019"))
print(withtitle)
这<h2>
会在打印时将标题标签和内容放在表格元素之前。
推荐阅读
- css - 位置问题:粘性和底部:0
- r - R:如何将 data.frame 拆分为具有 2 列的较小 data.frames
- python - 如何将 args 和 kwargs 传递给 setter
- r - 使用 R 中 tigris 包中的数据将邮政编码标签添加到传单
- python - 我们如何在数据框中拆分管道分隔字段?
- javascript - React JS - 在子点击时更改父状态,映射不可迭代
- java - 如何在 Wildfly 22 上配置 smtp 超时?
- ruby-on-rails - 如何比较包含数组的哈希但忽略数组内的顺序
- opengl - OpenGL glVertexArrayAttribBinding bindingIndex
- asp.net-mvc - 不同表共享相同字段时如何设计EF Core代码优先数据库