January 13, 2015

(This article was first published on numbr crunch - Blog, and kindly contributed to R-bloggers)

I finally finished my first Shiny application! You can click this link to check it out. Below is a screenshot of what it looks like.
I got all the data from the United States Census Bureau website. What the app does is provide a comparison of average income by race for different income groups between 1972 and 2013. If that doesn’t make much sense, go play around in the app. 

All the code for the app can be found here.

On the census bureau website, all the data is provided by race. For each of the income groups, I took the specific race data and combined it into a spreadsheet. Hence there are seven spreadsheets, one for each income group. The income group “Average” is actually not part of the original data, I averaged the data from the 5 existing quintiles to create the data for that spreadsheet. You’ll also notice that the census data includes two white categories: “White” and “White, Not Hispanic”. For the purposes of this visualization, I tried to separate all the data by race so the white category used is “White, Not Hispanic”. 

Development Hurdles
This application was developed completely in R. I’m using the Shiny package to create the visualization. Shiny uses a ui and a server file to create a reactive application. What is a reactive application? It’s an application that changes on the fly based on the current inputs. There’s a lot of great documentation on how to develop Shiny applications, check out their main website for more details. If you have a little money to spare, there is a pretty good R tutorial available on Udemy as well. The only thing that really caused me to stumble was the reactive functions in R. Reactive functions create reactive function variables. For example, the first input in my app is “race”, which can be any combination of 0 to 5 options. This vector is actually a function variable as opposed to a standard variable. This means that you have to call it in its function form, so “race()” as opposed to “race”. This tripped me up initially but once you get passed that, Shiny is a fun and not too difficult way to create some pretty cool visualizations.

Hosting Issues
This was another unexpected hurdle I hit. Shiny server does offer the ability to host Shiny apps but unless you are a student or teacher, it’s pretty expensive. Since I’m using Weebly for my blog which basically steps in for all the complex hosting duties, I had to host this app elsewhere. The Udemy class I purchased above promised a lesson on how to host on Amazon EC2 from Mac OSX but the documentation was outdated so I ended up having to figure it out by myself. Long story short, with quite a bit of effort, I successfully got it hosted on Amazon EC2. I noted the steps so when I have time, I’ll include an A to Z hosting guide for OSX on the blog.

To leave a comment for the author, please follow the link and comment on their blog: numbr crunch - Blog. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)