RStudio 查看器窗格不起作用? [英] RStudio Viewer Pane not working?

查看:57
本文介绍了RStudio 查看器窗格不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试学习 R 来进行一些网络分析.我找到了 networkD3 包并运行了他们的示例代码(如下)来熟悉.它会切换到控制台右侧的查看器"选项卡,但它会显示为空白.如果我使用导出 -> 另存为网页...",那么我可以在浏览器中打开该保存的 html 文档并查看我希望看到的内容.

I have been trying to learn R to work on some network analysis. I found the networkD3 package and ran their example code (below) to get acquainted. It would switch to the "Viewer" tab on the right side of the console, but it would appear blank. If I used the "Export -> Save As Web Page..." then I could open that saved html document in my browser and see what I expected to see.

我尝试了其他一些我认为会在该查看器窗格中打开的内容,但它会在我的浏览器中启动一个选项卡.我什至尝试过 rstudio::viewer("document.html") 方法,它仍然进入我的浏览器.有什么想法吗?

I've tried a couple other things I think would open in that Viewer pane but it launches a tab in my browser. I've even tried the rstudio::viewer("document.html") approach and it still goes to my browser. Any ideas?

# Create fake data
src <- c("A", "A", "A", "A", "B", "B", "C", "C", "D")
target <- c("B", "C", "D", "J", "E", "F", "G", "H", "I")
networkData <- data.frame(src, target)

# Plot
simpleNetwork(networkData)

推荐答案

看来,为了使内部查看器正常工作,您的源文档必须实际上驻留在会话临时目录" - 如支持文档.因此 - 假设您的主目录中有一个文件 test.html - 以下内容将在您的默认浏览器中打开该文件...

It appears that in order for the internal viewer to work, your source documents must actually reside in "the session temporary directory" - as stated in the support document. Thus - assuming you have a file test.html in your home directory - the following will open the file in your default browser ...

myViewer <- getOption("viewer")
myViewer("~/test.html")

...但要在内部查看器窗格中打开它,您需要:

... but to open it in the internal viewer pane you need this:

file.copy("~/test.html", file.path(tempdir(), "test.html"))
myViewer(file.path(tempdir(), "test.html"))

这也适用于 .jpg 但不适用于 .pdf(.pdf 在您的默认 pdf 查看器中打开.)顺便说一句,file.show() 具有相关功能:它将在编辑窗格中打开 .html 和 .jpg 文件 - 但也不会打开 .pdf.

This also works with .jpg but not with .pdf (.pdf's open in your default pdf viewer.) Incidentally, file.show() has related functionality: it will open .html and .jpg files in the edit pane - but not .pdf either.

这篇关于RStudio 查看器窗格不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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