Creating Shiny Apps

R. Peek
27 Jan 2014

What is Shiny?

A way to build web applications without having to learn/know JavaScript, HTML, etc.

  • Instantly updates, outputs change as users modify inputs, without requiring a reload of the browser.
  • Build it with R! using “reactive expressions”
  • Runs in any R environment( Console R, Rgui for Windows or Mac, ESS, StatET, RStudio, etc.)
  • Can be hosted on a server or sign up with shinyapps.io

Building a Shiny App: what's needed

2 main files required, a few extras to make things fancy:

  • ui.R this is the user interface file, which defines how your app will look and serves as the outline for…
  • server.R this is the server file which looks for what the user selects (defined in the ui.R) and performs specified operations on the data

  • Some extra options:

    • global.R A place to load data, packages, and global components of your app
    • about.R A separate R script that essentially is a custom HTML for a specific “tab” in your app

Examples of Shiny Apps

RStudio Tutorial

I definitely recommend reading through the RStudio tutorial, it has many useful examples. (http://rstudio.github.io/shiny/tutorial/#)

install.packages("shiny")
library(shiny)

River Thermohydrographs

This is an example using data collected at the Center for Watershed Sciences, I build the app because I often get requests for temperature data for a study site. This provides a great way to both visualize, aggregate, and export data.

One issue I ran into related to the default app size, but it was easy to adjust using:

runApp(appDir= "PATH/PROJECTS/thermohydrographs")
deployApp() # the app I used was too large for the default container...so...
configureApp("thermohydrographs", size=medium)