This website is generated using RMarkdown.

RMarkdown is great for creating quick professional looking reports, with embedded R function output with or without the code that created them.

You can schedule reports by scheduling the RMarkdown document like you would any R script.

Options include: PDFs, HTML, MS Word, Slides, books, websites (like this one).

By default, a new RMarkdown document will contain the text below (shown in light gray).


R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots. For example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.


Shiny

Shiny is a web application framework for R, produced by RStudio.

A Shiny app usually has two files, server.R and ui.R. These take care of the web server backend and the HTML frontend, respectivily.

To run a Shiny app you need to have a Shiny server running. RStudio comes with one pre-installed for running your apps locally, but for publishing you will need to install Shiny server or host via shinyapps.io.

Shiny apps use a functionality called reactivity that means that apps can be quick and responsive to changes to inputs. This is one of the best features of Excel, where changing one cell can have consequences throughout the Workbook.

Shiny apps can be tricky to get your head around due to the fact that they have a different work flow from normal R programs. It’s recommended to go through the tutorials online.

Combining RMarkdown and Shiny

A recent development is the ability to put Shiny elements into an RMarkdown document.

These documents, again, need a Shiny server to run, but take advatage of the easy formatting of RMarkdown to present the user interface - server and UI elements sit in the same document.

An example RMarkdown document with a Shiny element taking care of authentication can be found here.

Shiny or RMarkdown?

There are a few options for data presentation using R so an overview is first presented to help you decide which to choose.

Name Interactive Output Ease of use Cost Server needed?
Shiny Server-side and client-side HTML Advanced Free for Shiny Server, $9995 for Shiny Server Pro, $9+ a month Shinyapps.io Yes
RMarkdown client-side only HTML, PDF, Word, etc. Easy Free, can also publish to a Shiny server Only a normal HTML server if you want to host those (e.g. Github Pages lets you host for free)
Flexdashboard Server-side and client-side HTML Easy Free, can also publish to a Shiny server If using Shiny elements, yes

It generally comes down to the amount of interactivity you need in your app. For a full solution where data is updated and processed in real-time, Shiny is your best option. If you just need a nice format for presentation offline, then RMarkdown can produce some very nice looking formats.

Flexdashboard is a bit of both - it is essentially an RMarkdown document that allows Shiny elements to be placed within it.

All the above is further complicated by HTML Widgets - these render in JavaScript that can do a lot of interactivity by itself, so if you can find a JavaScript library that gives you say dropdowns, then you can use that in RMarkdown instead of using Shiny, without hosting a Shiny server.

Shiny

Shiny is a R package by RStudio that lets you run reactive apps on a special Shiny server.

Shiny server

A Shiny server can be installed on a dedicated machine, or it comes bundled with RStudio for local testing. Before you deploy an app online you will need to have a Shiny server available to publish to. At the moment your options are:

Reactive apps

Shiny uses a special approach known as reactive in making its apps. This allows for very responsive applications. A typical Shiny app has two elements - a UI script that is in charge of rendering the HTML front end, and a server script that takes care of which R code is run when elements on the UI change.

RMarkdown

RMarkdown takes a different approach - it renders a special flavour of Markdown into a standard format, which is then in turn rendered into the end product. The end product varies between HTML, PDF, Word etc.

Because the end product has no link with the code made to create it, you can’t call R functions from a final RMarkdown product. However, you can render using JavaScript that can interact with the data on the page in real-time (for HTML apps, it obviously wouldn’t work with a PDF!)

This documentation is written in RMarkdown, as an example.

Flexdashboard

Flexdashboard is a bit of both. You write pages in RMarkdown that can include Shiny elements. If you do incude Shiny elements, then when you publish, flexdashboard uses RMarkdown to create the HTML, and then runs a Shiny server to provide the elements.