Web Enable R models with Shiny

24. March 2014 00:19 by Jay Grossman in   //  Tags:   //   Comments (0)

Last September I was preparing for my fantasy football league and I found this really cool web app that suggested the optimal draft recommendations based on the rules of your league. I then found the associated article on r-bloggers that explained how it was done:


Shiny is the secret sauce to make this possible:

The Shiny package makes it super simple for R users like you to turn analyses into interactive web applications that anyone can use. Let your users choose input parameters using friendly controls like sliders, drop-downs, and text fields. Easily incorporate any number of outputs like plots, tables, and summaries. No HTML or JavaScript knowledge is necessary. If you have some experience with R, you’re just minutes away from combining the statistical power of R with the simplicity of a web page.

So Shiny takes advantage of a familiar Client-Server pattern. The package will generate HTML layout and javascript code (I see includes for bootstrap.js), that calls wraps calls to our R logic

CRAN has the full reference for the shiny package. Download pdf here


Nice Intro to Shiny

This week I got an email from Vivian Zhang that she was going to introduce Shiny as part of her weekly NYC Open Data meetup. Since it was walking distance from my office, I decided to attend. She posted a blog entry that does a pretty good job detailing the session (along with a video of the entire 2 hour session):


The project for the class was to create a Shiny project to run linear regression and return the summary and plot of the summary. I was able to solve this and Vivian included my code.

So here are the key takeaways:

  • You need R version 3.0+. Download here
  • You need R-Stuidio. Download here
  • The Shiny tutorials and examples are available on the rstudio site, and they are really helpful
  • You'll need to create ui.R script. This is where you define the form controls (dropdown lists, numeric inputs, text boxes, check boxes, radio buttons, file upload) and the output panels to display the results of your models (text, tables, plots). 
  • You'll need to create server.R script. This script takes in the form inputs, processes logic, and returns the content to output to the user.
Fun toy I built with Shiny

Last June I did some work using R to build models to predict Ebay Sales. I thought this would be a really great opportunity to use Shiny to web enable those models.

On Thursday (3/27), I was able to create the Shiny app show below on my round trip train commute in one day (roughly 2 hours): 

click to see full screen view

The user is prompted to:

  1. select a player
  2. select the category
  3. enter the seller's ebay id
  4. indicate whether item is authenticated
  5. enter the minimum bid
The application returns:
  1. historical sales reference info for the sku (player+category)
  2. the predicted probability that the listing will result in a sale
  3. the predicted sale price and predicted price bucket (category)
I have shared my code and a very limited sample data set on github at:
This is little app is going to make it so much easier for me to determine deals on eBay, as it's much easier than munging some data and firing up R on the command line,

About the author

Jay Grossman

techie / entrepreneur that enjoys:
 1) building software projects/products
 2) digging for gold in data
 3) rooting for my Boston sports teams:New England PatriotsBoston PatriotsBoston Red SoxBoston CelticsBoston Bruins

Month List