Aloha jcblum:
you made me review (again) the RStudio Extensions page for RStudio Viewer
URL: https://rstudio.github.io/rstudio-extensions/rstudio_viewer.html
which suggests the following code for viewing [a file] in the RStudio Viewer pane:
tempDir <- tempfile()
dir.create(tempDir)
htmlFile <- file.path(tempDir, "index.html")
# (code to write some content to the file)
viewer <- getOption("viewer")
viewer(htmlFile)
OK not the fastest thinker, it took me time to connect dots and realize: I have to make that htmlFile have real content - the contents of the actual .html file I just rendered from RMarkdown
The solution is as simple as using file.copy()
Step by Step:
I capture the name of the just-generated-from-Rmd .html file in x
then I use the generic RStudio Viewer code which creates a still-generic htmlFile in the tempDir
and THEN I copy the real .html file (x) to this abstract file named htmlFile
and FINALLY I view it - in the Viewer pane.
x <- "RMD-Demo-Viridis-002x.html"
tempDir <- tempfile()
dir.create(tempDir)
htmlFile <- file.path(tempDir, x)
file.copy(x, htmlFile)
# (code to write some content to the file)
viewer <- getOption("viewer")
viewer(htmlFile)
So it boils down to the obvious:
where the generic template code has a comment line:
# (code to write some content to the file)
I replaced it with my file.copy() command:
file.copy(x, htmlFile)
Voila: solution to viewing a (small) .html file generated from RMarkdown in the Viewer pane.
Next: how to view the .html file in a separate Rstudio popup window (my preference)
Thank you all for responding so quickly.
AW