Web Enable R models with Shiny
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:
http://www.r-bloggers.com/win-your-fantasy-football-snake-draft-with-this-shiny-app-in-r/
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):
http://www.nycopendata.com/2014/03/25/building-interactive-web-app-with-shiny/
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.
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):
The user is prompted to:
- select a player
- select the category
- enter the seller's ebay id
- indicate whether item is authenticated
- enter the minimum bid
The application returns:
- historical sales reference info for the sku (player+category)
- the predicted probability that the listing will result in a sale
- the predicted sale price and predicted price bucket (category)
I have shared my code and a very limited sample data set on github at:
https://github.com/jaygrossman/EbaySalesPredictionShiny
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,