# How to create a choropleth with dash

**URL:** <https://community.plotly.com/t/how-to-create-a-choropleth-with-dash/51370>\
**Category:** Dash Python\
**Created:** [March 24, 2021, 6:34pm UTC](https://community.plotly.com/t/how-to-create-a-choropleth-with-dash/51370 "2021-03-24T18:34:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![manelalayet](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@manelalayet](https://community.plotly.com/u/manelalayet)\
**Post date:** [March 24, 2021, 6:34pm UTC](https://community.plotly.com/t/how-to-create-a-choropleth-with-dash/51370/1 "2021-03-24T18:34:42Z")

</div>

another newbie question 😃  
how can I create a chropleth map from a geojson and a csv file using dash ☹ i created it using plotly express and when i try to add it as a dcc.graph components this the code from plotly express.

from urllib.request import urlopen

import plotly.offline as offline

import geojson

import pandas as pd

import plotly

import plotly as plt

import plotly.express as px

from plotly.offline import download\_plotlyjs, init\_notebook\_mode, plot, iplot

```
                #define data frame using pandas lib and display data for population in Tunisia 

```

df = pd.read\_csv(“py/tngov -1.csv”)

print(df)

```
                        #Geojson data from url source 

```

with urlopen(‘[http://www.openculture.gov.tn/dataset/70fd9b49-3925-477f-ae17-9d206d650aab/resource/4b3d85dd-a523-425c-b477-ab9fec6e51a0/download/decoupage.geojson](http://www.openculture.gov.tn/dataset/70fd9b49-3925-477f-ae17-9d206d650aab/resource/4b3d85dd-a523-425c-b477-ab9fec6e51a0/download/decoupage.geojson)’) as response:

```
cities = geojson.load(response)

```

print(cities[‘features’][0])

```
                                #choropleth map

```

fig= px.choropleth\_mapbox(df, geojson=cities,locations=‘id’, color='population ',

color\_continuous\_scale=“Viridis”,hover\_name = ‘deleg\_na\_1’, hover\_data =[“gov\_name\_f”,“gov\_id”,"population "],

labels={‘population’:‘population number’}, mapbox\_style=“carto-darkmatter”,zoom=4,

center = {“lat”: 36.82189, “lon”:10.168969 })

fig.show()

plt.offline.plot(fig, filename = ‘map.html’)

---

<div class="post-metadata">

**Author:** ![Emily24](https://avatars.discourse-cdn.com/v4/letter/e/6bbea6/32.png) [@Emily24](https://community.plotly.com/u/Emily24)\
**Post date:** [March 26, 2021, 9:53am UTC](https://community.plotly.com/t/how-to-create-a-choropleth-with-dash/51370/2 "2021-03-26T09:53:18Z")

</div>

Hey,

Here I explain how to make a choropleth map:

> **[espayne/Choropleth-Mapping-UK-python-](https://github.com/espayne/Choropleth-Mapping-UK-python-)**
>
> Geographical mapping in python using UK GeoJSON files

In terms of adding it to dash, since it is a plotly graph you can simply use  
dcc.Graph(id=‘map’, figure={}) in your layout

and then in your call back

Output(component\_id=“map”, component\_property=‘figure’

---

<div class="post-metadata">

**Author:** ![manelalayet](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@manelalayet](https://community.plotly.com/u/manelalayet)\
**Post date:** [March 30, 2021, 4:00pm UTC](https://community.plotly.com/t/how-to-create-a-choropleth-with-dash/51370/3 "2021-03-30T16:00:12Z")

</div>

Thanks i’ll try this
