Embedding Shiny Apps Inside R Markdown Documents

I’d read about ‘interactive’ documents before, and saw a presentation that used them at the Shiny Developer Conference. Thought it was a cool idea but figured it was too complicated to put into practice.

All it takes is one extra line in the YAML front matter for the R Markdown:

runtime: shiny

… and that’s pretty much it.

To host the document you do need a Shiny Server running on top of a version of R with the rmarkdown package installed. But besides that there’s no additional server configuration necessary. The main thing to note is that you don’t actually knit the document to HTML to host it. Just drop the .Rmd file in a subdirectory of your shiny-server root (i.e. where you keep all of the other apps) and the Shiny Server will take care of the rest.

Here’s an example .Rmd.

Related