Python Dash app for NYC Tree Health

How to create a dash choropleth map to filter your visualization

Justin Morgan Williams


Photo by Lerone Pieters on Unsplash


Think of all the trees in the New York City (NYC) that help sequester carbon so that New Yorkers can breath some semblance of clean air. Without them, we would be screwed, bottom line — NYC Tree Health is important.

In 2015 NYC Parks & Recreation organized a large scale data collection conducted by volunteers and staff, which included tree species, diameter and health perception. This data is publicly available on NYC Open Data.

I wanted to create an interactive dashboard to analyze overall tree health, and see if steward quantity has a positive impact. I also wanted to implement this without using any local data, and filter the subsequent findings via map. I figured Dash would be up for the challenge, So here goes!


Socrata API

As stated prior, I wanted to write code that pulls all needed data directly from the web, without a need for local storage, this is where the Socrata API comes in handy. It enables one to to use “Socrata Query Language” or SoQL to query the data, obtaining only the information absolutely necessary for analysis. This eliminates the need to download the entire dataset (in this case ~684 rows or trees), which could overwhelm the app and cause processing delays. It is much like SQL, and the basics are outlined here.

Here is the call actually utilized for part of the dataset:

Here we build the base url and append the query with the SoQL $select statement for:

  • spc_common — Tree species
  • boroname — Borough within NYC
  • tree_id — Distinct tree identifier

The COALESCE statement converts the spc_commonNaN’s to categorical, whereas the COUNT statement counts the tree_id. Then the SUM, CASE WHEN statements sum up each value in the health column…



Justin Morgan Williams

Data scientist passionate about the intersectionality of sustainability and data.