Rstudio Viewer Pane Not Working

RStudio Viewer Pane not working?

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.

How to activate Rstudio Viewer pane for rmarkdown xaringan slide?

Go to the menu: Tools -> Global Options -> R Markdown -> Show output preview in [Viewer Pane].

Or use xaringan::inf_mr().

Open R Markdown in viewer pane

Follow the instruction described by @J_F and click the Knit to HTML button. Preview will be displayed in the viewer pane.
https://rmarkdown.rstudio.com/articles_integration.html

displaying ggplot .png in RStudio viewer pane with correct dimensions

The resolution needs to match that of your device. Default dpi is 300 in ggsave, but monitors are typically 96 dpi:

dims <- dev.size(units = "in")
plt_path <- tempfile(fileext = ".png")
ggsave(plt_path, plt, width = dims[[1]], height = dims[[2]], units = "in",
dpi = 96)

viewer <- getOption("viewer")
viewer(plt_path)

Sample Image



Related Topics



Leave a reply



Submit