Embedded Shiny Map Application

Maps of Illinois Natural Hazards by County

I remember noticing somewhere that it was possible to embed a Shiny application into a webpage created via the R blogdown package. I thought it would be interesting to attempt to do this for a blog post.

I did some investigating and I found information here on how to do it. Once my Shiny application was deployed, I only needed a couple of lines of code in the R markdown webpage file to make it work.

In order to create the Shiny application, I decided to leverage the map making knowledge I acquired while writing this post. I thought it would be nice to use Shiny to allow the user to interact with some maps by toggling between options from a drop down menu.

Next, I needed some data, so I went digging around the FEMA website. FEMA (Federal Emergency Management Agency) is the U.S. government agency responsible for helping people before, during and after disasters. They publish a national risk index for natural hazards, encompassing the 18 most common natural hazards. This index is helpful to anyone who is trying to understand the natural hazard risk in a community by providing a baseline relative risk measurement for each U.S. county and census tract.

FEMA also make their data available at the county and census tract levels in table format (‘.csv’), which is exactly what I need for my Shiny application project. I downloaded the Illinois county level dataset. It contains a lot of modeled values around risk probabilities and associated valuations. How these numbers were created is quite technical. Therefore, the metric I selected was the annualized number of events for each natual hazard type, as this is more straightforward to understand.

In order to create the Shiny application, I made two maps of Illinois using shapefiles from the tigris package. I joined these maps to the Illinois FEMA data at the county level. Then I made a couple of tab panels in Shiny to view the maps based on the natural disaster type. Once I was happy with it, I deployed it to shinyapps.io.

I have used Shiny before for a couple of small projects, so it didn’t take me too long to make this application. However, my knowledge of Shiny at the moment doesn’t extend too much beyond this. I would really like to dedicate some time to building a comprehensive Shiny application, to further my knowledge in this area. It is definitely on my to do list, so it is likely that I’ll tackle this at some point in the future. I’ll make sure to write a few posts about the process when I do.

Conor Buckley
Conor Buckley

My interests include data wrangling, using the R tidyverse, and making insightful charts.