首页 > 解决方案 > 有没有办法将 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() 之上创建另一个表。

标签: rrcloud

解决方案


这适用于 RCloud notebook.R 笔记本:

library(knitr)
run <- function(...) {
  x = kable(mtcars, format = 'html',  table.attr = 'id=\'mytable\'')
  out(x)
  done()
}

推荐阅读