Interactive Map in R with Shiny and Leaflet

health analytics
data science
data wrangling
R
data visualization
Shiny apps
Leaflet
An interactive map of CDC health data using Shiny and Leaflet in R. Explore nutrition, exercise, and obesity trends across U.S. states.
Author

Oliver F. Anderson, MS

Published

November 23, 2022

Keywords

R, Shiny, Leaflet, interactive map, CDC data, public health, data visualization

This project uses Shiny and Leaflet in R to create an interactive map of CDC data on nutrition, exercise, and obesity across the United States. The app was developed in partnership with Hayden Vaughn and is hosted on shinyapps.io.

You can explore the live version here:
👉 Full Shiny App

Workflow

  1. Data source
    • CDC public health dataset covering state-level nutrition, physical activity, and obesity indicators.
  2. Shiny application
    • Built with shiny for the app structure and reactivity.
    • User interface allows selection of different health indicators.
  3. Leaflet map
    • Used leaflet for the interactive choropleth map.
    • States are shaded according to health indicator values, with hover/click tooltips.
  4. Deployment
    • Hosted on shinyapps.io for public access.

Application Preview

Discussion

The finished application allows users to explore public health trends interactively. By selecting variables, users can compare how nutrition, exercise, and obesity differ across states.

This project highlights how R’s Shiny and Leaflet packages can be combined to produce data-driven tools for public health communication.

FAQ: Building Interactive Maps with Shiny and Leaflet

How do I add an interactive map to a Shiny app?

Use leafletOutput() in the UI and renderLeaflet() in the server function.

How do I color states or regions by value?

Create a color palette with colorNumeric() or colorBin() and apply it to polygons.

Can this app be deployed for free?

Yes. Shiny apps can be deployed to shinyapps.io with a free plan, though usage limits apply.

What types of datasets work best with Leaflet?

Any dataset with geographic boundaries or coordinates, such as shapefiles, GeoJSON, or state/county-level data.

Oliver F. Anderson, MS – Computational Biologist, Data Scientist, and Research Consultant based in Portland, Oregon. I design data-driven solutions in bioinformatics, machine learning, and AI automation for research and biotech.

Back to top