Hi
I am trying to display a choropleth_mapbox map with geojson in a dash app.
I first wrote a plotly function that generate my figure and I get exactly what I want :
from urllib.request import urlopen
import json
import pandas as pd
import numpy as np
import plotly.express as px
with urlopen('https://raw.githubusercontent.com/gregoiredavid/france-geojson/master/departements-version-simplifiee.geojson') as response:
geojson = json.load(response)
df = pd.DataFrame([x['properties'] for x in geojson['features']])
df['randNumCol'] = np.random.randint(0, 10, df.shape[0]).astype('str')
fig = px.choropleth_mapbox(df, geojson=geojson, featureidkey='properties.code', locations='code',
color="randNumCol", center = {"lat":47, "lon":2}, zoom=4.3, mapbox_style="carto-positron",
opacity=0.5)
fig.update_layout(mapbox_style="open-street-map",
showlegend=False,
margin={"r":0,"t":0,"l":0,"b":0},
width=600,
height=500
)
fig.show()
And I get a school map with the french departments
I now try to use this map in a Dash app. I directly used this figure and try not to modify it
import json
from urllib.request import urlopen
import dash_core_components as dcc
import numpy as np
import pandas as pd
import plotly.express as px
from dash import Dash
with urlopen('https://raw.githubusercontent.com/gregoiredavid/france-geojson/master/departements-version-simplifiee.geojson') as response:
geojson = json.load(response)
df = pd.DataFrame([x['properties'] for x in geojson['features']])
df['randNumCol'] = np.random.randint(1, 10, df.shape[0]).astype('str')
fig = px.choropleth_mapbox(df, geojson=geojson, featureidkey='properties.code', locations='code',
color="randNumCol", center = {"lat":47, "lon":2}, zoom=4.3, mapbox_style="carto-positron",
opacity=0.5)
fig.update_layout(mapbox_style="open-street-map",
showlegend=False,
margin={"r":0,"t":0,"l":0,"b":0},
width=600,
height=500
)
app = Dash()
app.layout = dcc.Graph(id="graph", figure=fig)
if __name__ == '__main__':
app.run_server(debug=True)
This time I get this image without the colored geojson defined regions:
Do you have an idea of what I do wrong ?
Thanks a lot for your help