Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
738 views
in Technique[技术] by (71.8m points)

r - RStudio Viewer Pane not working?

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.

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"))

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...