Tomas Greif
Tomas Greif

Reputation: 22623

RStudio - render html content in viewer pane

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

Upvotes: 6

Views: 6230

Answers (1)

J. Win.
J. Win.

Reputation: 6761

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.

Upvotes: 1

Related Questions