Visualize Parks and Racial Distribution in NYC with Dash
I had envisioned a Dash app where one could hover over a choropleth map and trigger changes in the the dashboard, however, I also wanted a dropdown selector, that would trigger the same response. Essentially, I wanted to create an output, that had multiple inputs, and I needed to specify which input fired, to elicit the correct output response. I wasn’t able to get this to work with basic callback features. This took endless trial and era to complete (the documentation for advanced callback features isn’t that explicit), so I figured I would dedicate a blog to this app, with multiple input advanced callbacks being the focal point.
I wanted to show proportion of parks within each NYC Community District Tabulation Area (CDTA), juxtaposed against racial distribution. The intention was to be exploratory in nature, allowing one to view the different demographics in each CDTA, and parks.
The Parks Properties dataset identifies property managed partially or solely by NYC Parks. We download the shapefile directly to our notebook as a GeoDataFrame with GeoPandas. Then, convert the coordinate reference system (CRS) to New York State Plan 2263 (this is the preferred CRS used by NYC governmental entities).
import geopandas as gpd
# define url
parks_url = 'https://data.cityofnewyork.us/api/geospatial/enfh-gkve?method=export&format=Shapefile'
gdf_parks = gpd.read_file(parks_url) # import shapefile as gdf
# change crs
# preview gdf
Preview the GeoDataFrame:
Let’s create a simple plot using the contextily package for a base map.