External resources are not generally HTML-addressable in Shiny docs
In Shiny documents, it's possible to refer to external images using traditional Markdown syntax, but most other references to external resources don't work: for example <iframe>, <embed>, and <object> don't work, as do ordinary images if they reorder attributes (e.g. <img alt="hello" src="hello.jpg"/>).
This situation arises because of the way Shiny documents are rendered. They are knitted and converted to HTML in a temporary folder, and served from that temporary folder. In the special case of images (see copy_resources in html_document_base), we scrape the document and copy the resources to the temporary folder so that they can be addressed in the converted HTML. However, this approach can't be fully generalized without writing HTML regex rules for every possible syntax that could refer to an external resource.
One solution might be to use a Shiny resource handler that can serve resources out of the document folder; another might be to attempt to scan very generically for known source attributes. A couple things to keep in mind:
- Shiny Server already uses
<base href/>, so that tool isn't available to remap addresses. - We don't want to write a resource handler that makes it possible for a web browser to read arbitrary content from the Shiny document's source folder (for obvious security reasons).
Another pattern which deserves attention is the use of includeHTML. We rely on static analysis of the Rmd file to fix resource references in Shiny documents. Since HTML injected this way is only present at runtime (i.e. when the document's R code is run), none of the files it references are going to be captured. Note that none of the "automatic resource capture" mechanisms, however clever, will address this use case, since they all operate on a copy of the document that hasn't yet executed any R code.