是否可以在查看器窗格中查看 HTML 表格? [英] Is it possible to view an HTML table in the viewer pane?
问题描述
我想知道是否有任何功能可以轻松地在 RStudio 的查看器窗格中可视化 html 对象.例如,我想知道是否可以在查看器窗格中查看 html 表.
I would like to know if there is any function which makes it easy to visualize an html object in the RStudio's viewer pane. For instance, I would like to know if it would be possible to view an html table in the viewer pane.
library("Quandl")
library("knitr")
df <- Quandl("FBI_UCR/USCRIME_TYPE_VIOLENTCRIMERATE")
kable(head(df[,1:9]), format = 'html', table.attr = "class=nofluid")
推荐答案
这是在 RStudio 中执行此操作的快速方法
Here is a quick way to do this in RStudio
view_kable <- function(x, ...){
tab <- paste(capture.output(kable(x, ...)), collapse = '\n')
tf <- tempfile(fileext = ".html")
writeLines(tab, tf)
rstudio::viewer(tf)
}
view_kable(head(df[,1:9]), format = 'html', table.attr = "class=nofluid")
如果kable
函数可以返回kable
类的对象,那么可以将view_kable
重命名为print.kable
在这种情况下,只需调用 kable
函数即可在查看器中打开表格.如果您认为这很有用,请继续在 knitr
github 页面上提交功能请求.
If the kable
function can return an object of class kable
, then one could rename view_kable
as print.kable
in which case merely calling the kable
function would open the table in the viewer. If you think this is useful, please go ahead and file a feature request on the knitr
github page.
这篇关于是否可以在查看器窗格中查看 HTML 表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!