-
-
Notifications
You must be signed in to change notification settings - Fork 975
rmarkdown::run and external resources
When you use rmarkdown::run
to view an interactive presentation or document, you may notice that your references to external resources don't work, even if those references work in non-interactive documents.
For example, suppose you have a .html
file alongside your R Markdown document, and you'd like to show it in a frame in the document:
# myfile.Rmd
## Enjoy this embedded graph
<iframe src="external.html"/>
This works fine in static R Markdown documents, but doesn't work in interactive R Markdown documents (i.e. documents containing runtime: shiny
).
> rmarkdown::render("myfile.Rmd") # Frame visible
> rmarkdown::run("myfile.Rmd") # Frame not visible
When you use rmarkdown::run
(or the Run Document button in RStudio), this is what's happening beneath the covers:
- Your R Markdown document is rendered to a temporary folder on disk.
- A Shiny web server is started to serve content from the temporary folder.
- A browser is opened and connected to the Shiny server.
In the example above, the file external.html
doesn't exist in the temporary folder, so when the browser tries to load it, it won't be able to find it.
In order to make files from the document's original folder addressable in the rendered document, it would be necessary for the web server to expose that entire folder via HTTP. This isn't impossible but has significant security implications.
Currently, the best workaround is to host the external resources elsewhere, and reference them using absolute URLs (i.e. starting with HTTP or HTTPS).
## Enjoy this embedded graph
<iframe src="http://myhost.com/mydir/me/external.html"/>
In the next few months we're hoping to design a mechanism by which you can declaratively describe your document's dependencies and selectively expose external resources, so that it's possible to use relative URLs in interactive documents without exposing entire host folders on the Shiny web server.
Watch this issue for status: #139