How to create a choropleth with dash

another newbie question :smiley:
how can I create a chropleth map from a geojson and a csv file using dash :frowning: 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 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”)


                        #Geojson data from url source 

with urlopen(‘’) as response:

cities = geojson.load(response)


                                #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 })

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


Here I explain how to make a choropleth map:

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’

Thanks i’ll try this