r - 有没有办法将 CSS ID 添加到 R FastRWeb otable() 输出,以便可以使用 DatablesJS 对其进行格式化?
问题描述
DataTables JS 需要一个格式良好的 HTML 表格,其中包括一个表格 id 和一个 tag。
是否可以将这些添加到 FastRWeb otable() 输出中,以便可以使用 DataTables JS 格式化输出?我使用 RCloud notebook.R Web 服务接口调用它,所以我需要使用 FastRWeb 库。
我尝试在表格前添加一个 out() :
library(FastRWeb)
run <- function(...) {
out("<thead><tr><th>Column 1:</th><th>Column 2:</th></tr></thead>")
d <- data.frame(a = 1:3, b = c("foo", "bar", "foobar"))
otable(d)
done()
}
但是,这会在 otable() 之上创建另一个表。
解决方案
这适用于 RCloud notebook.R 笔记本:
library(knitr)
run <- function(...) {
x = kable(mtcars, format = 'html', table.attr = 'id=\'mytable\'')
out(x)
done()
}
推荐阅读
- javascript - 移动多个元素并将它们放回原处
- c# - MvvmCross WPF - 多窗口应用程序 (MvxWindow)
- mysql - NOT IN 运算符的 SQL 查询
- agda - 是否可以仅使用函数和 Sigma 来实现 Bool?
- aframe - Aframe:是否可以禁用版本记录
- google-bigquery - BigQuery 的 ARRAY_AGG 函数中“ORDER BY”的错误行为
- c# - 使用 Power BI Rest API 嵌入非组工作区报告
- rabbitmq - rabbitmq 联合交换可扩展性
- google-sheets - 根据下拉选择创建图表?
- c++ - 在 std::deque 中移动元素的有效方法?