R Markdown documents are a perfect platform for interactive content. To make your documents interactive, add:

  1. Interactive JavaScript visualizations based on htmlwidgets, or
  2. Reactive components made with Shiny

htmlwidgets

Htmlwidgets are R functions that return JavaScript visualizations. The document below uses a leaflet htmlwidget to create an interactive map.


Htmlwidgets create client side interactions. Since htmlwidgets are exported in JavaScript, any common web browser can execute the interactions.

Learn more about packages that build htmlwidgets at www.htmlwidgets.org.

Shiny

The Shiny package builds interactive web apps powered by R. To call Shiny code from an R Markdown document, add runtime: shiny to the header, like in this document.


Use Shiny to run any R code that you like in response to user actions. Since web browsers cannot execute R code, Shiny interactions occur on the server side.

Learn more about Shiny at the Shiny Development Center.

Output formats

Htmlwidgets and Shiny elements rely on HTML and JavaScript. They will work in any R Markdown format that is viewed in a web browser, such as html documents, notebooks and websites, as well as dashboards and slide presentations.

If you include an interactive element in a static output format, like a PDF, R Markdown will embed a screenshot of the element.

Learn more about interactive documents with R Markdown at Interactive Documents.


comments powered by Disqus