Using Shiny to Analyze Salary Data
Shiny apps are simple web applications built using R or Python, though the latter is still early in development. They are fairly easy to put together with relatively few lines of code. I wanted to experiment with Shiny to show a disturbing pattern regarding salary data going back to 2003. I have read online many times about how average salaries have not increased in a while when adjusted for inflation, but I wanted to look at the data myself.
The Bureau of Labor and Statistics (BLS) makes its data publicly available, and they have an API that allows users to download their data using R. I used the BLS's API to download inflation data going back to 2003. I also downloaded salary over the same time overall and for the following occupation types:
I then built a simple Shiny app that plots yearly salary over time. The user can select which occupation type to plot, and check a box to plot an additional line for salary adjusted to 2003 dollars. You can access the Shiny app here: https://zachary-nabavian.shinyapps.io/Salary-Inflation/
I think the Shiny app speaks for itself. It's very clear that for any of the occupations listed above, salaries have increased since 2003, but inflation-adjusted salaries have barely moved. Keep in mind that I could only download data up to 2021. I wonder what this application would look like if I also included 2022. I may update this project later on when I can get more recent data.
There are other ways to visualize this data, but I like my Shiny app for a few reasons. Other approaches might clutter the graph with all of the occupations at once, which makes it harder to read. The Shiny app allows users to pick one occupation at a time. Also, this Shiny app tells a story in a unique way that makes the user an active participant. I designed this app so that a user will necessarily start by seeing how salaries have overall went up, but after clicking the "adjust for inflation" box they will notice that real salaries have barely budged. Then, the user can pick between many different occupations and see that the pattern persists throughout all of them.
领英推荐
Thanks for reading. I have posted relevant links below.
Data Scientist @ MD Anderson Cancer Center | Analytics Content Creator | Views are my own and do not represent my employer
1 年Thank you for the shout-out, Zachary! This is a great start. I hope to see more built on top of this app :)