RStudio - 在查看器窗格中呈现 html 内容 [英] RStudio - render html content in viewer pane

查看:90
本文介绍了RStudio - 在查看器窗格中呈现 html 内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 RStudio 查看器窗格中显示存储在我的工作目录中的 html 内容.我已阅读这篇文章 并认为这应该是可能的.

I would like to display html content stored in my working directory in RStudio viewer pane. I have read this post and thought this should be possible.

然而,本地文件总是在外部浏览器中呈现.有什么我遗漏的吗?

However, local files are always rendered in external browser. Is there anything I am missing?

# This will render in Viewer pane
tempDir <- tempfile()
dir.create(tempDir)
htmlFile <- file.path(tempDir, "test.html")
writeLines('<html><body>Hi there</body></html>', htmlFile)
rstudio::viewer(htmlFile)

# This will render in external browser
writeLines('<html><body>Hi there</body></html>', 'test.html')
rstudio::viewer('test.html')

推荐答案

根据您引用的链接:请注意,查看器窗格只能用于本地 Web 内容.此内容可以是写入到会话临时目录(即具有由 tempfile 函数生成的路径的文件)或本地运行的 Web 应用程序."

According to the link you referenced: "Note that the Viewer pane can only be used for local web content. This content can either be static HTML files written to the session temporary directory (i.e. files with paths generated by the tempfile function) or a locally run web application."

在您的第二个示例中,您试图在不在会话临时目录中的文件上使用查看器.

In your second example, you are attempting to use the viewer on a file that is not in the session temporary directory.

这篇关于RStudio - 在查看器窗格中呈现 html 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆