R and Shiny Web Applications
Shiny and R Talk @ Mango-Solutions
First up, we’re doing a talk on R, Shiny and Web Applications @ Chippenham Tech Chat on Weds June 19th 2013. More info here:
If you’ve not come across it Shiny is a reactive programming web application framework built around R for exposing analytic applications.
It’s made by the guys from RStudio, who also provide the great IDE that lots of us use.
An introduction to Shiny from RStudio:
http://rstudio.github.io/shiny/tutorial/
An introduction to Shiny from the Dallas R users group here:
https://github.com/trestletech/shiny-sandbox/blob/master/shiny_introduction.pdf
and a good overview of deploying Shiny on Amazon EC2 here:
http://www.r-bloggers.com/deploying-shiny-server-on-amazon-ec2/
I guess there’s a few notable things from my side that I thought were pretty great when working with Shiny.
Installation
Get up and running by installing with the following:
| Bash | | copy | | ? |
install.packages("shiny", repos="http://shiny.rstudio.com") |
and then run the example (starts a webserver on port 8100 and invokes xdg-open on Linux)
| Bash | | copy | | ? |
library(shiny) |
runExample("01_hello") |
Application Structure
The application consists of two main parts:
User Interface – ui.R
* Layouts
* Panels
* Inputs (selectInput, numericInput etc…)
Serverside – server.R
* function listeners
Architecture
The Shiny architecture is made up of a number of parts internally, namely a set of web/browser components including:
- Twitter Bootstrap – a UI library that provides scaffolding in terms of layouts with HTML and CSS
- Websockets – a way to do bi-directional communication with a browser/webserver.
Serverside Shiny makes use of Node.js for hosting (it doesn’t have to), but this to probably the most scalable approach.
Finally, it’s based on the concept of reactive programming which provides a number of parts:
- Triggers/Inputs – Source (Shiny Reactive Value)
- Sinks/Outputs – Endpoint (Shiny Observer)
The triggers are executed when dependencies (inputs) change resulting in a change to the output:
| Bash | | copy | | ? |
shinyServer(function(input, output) { |
output$plotOut <- renderPlot({ |
hist(faithful$eruptions, breaks = as.numeric(input$nBreaks)) |
if (input$individualObs) |
rug(faithful$eruptions) |
}) |
output$tableOut <- renderTable({ |
if (input$individualObs) |
faithful |
else |
NULL |
}) |
}) |
In some cases, changes could take a long time to run (accessing database, read from file). Shiny proposes conductors to encapsulate these operations. Shiny calls these reactive expressions
More info here – http://rstudio.github.io/shiny/tutorial/#reactivity-overview
Deployment
In terms of deployment you have a number of options:
1. You can deploy apps on hosted Shiny Server
2. Run from a Github paste (Gist) or from Github (this is an awesome feature)
| Bash | | copy | | ? |
shiny::runGist('3239667') |
shiny::runGitHub('shiny_example', 'rstudio') |
3. Deploy on Amazon EC2
4. Host yourself by installing Apache and NodeJS
Hope that gives you a good overview of Shiny, come along to the meetup if you want to learn more about it.
Recruitment Plug Here ->
Yeah, yeah we’re also recruiting for Java developers, Javascript developers for our devops and development teams here:
http://www.mango-solutions.com/careers.html
plus R developers : )
Our Stackoverflow company page is here – http://careers.stackoverflow.com/company/mango-solutions


