Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

Choropleth displaying on fig.show() but not on callback

Hey guys,

I got a problem concerning the rendering of a choropleth mapbox using graph objects in a dash callback.

The choropleth is showing empty on the callback like there is an ID error, but on a fig.show() triggered with the callback the map is shown perfectly.

Here is the code on this specific graph (zoom, lat and lon are dynamically defined)

tab3_content=dbc.Container(dbc.Row([
dcc.Dropdown(id='scoretab3',
    options=[

        {'label': 'Attractivité', 'value': 'SA'},
        {'label': 'Commerce', 'value': 'SC'},
        {'label': 'Jeune', 'value': 'SJ'},
        {'label': 'Grand Public', 'value': 'GP'},
        {'label': 'Haut de Gamme', 'value': 'HDG'},
        {'label': 'Pro', 'value': 'PRO'},
        {'label': 'Population', 'value': 'P16_POP'},
        {'label': 'Boulangerie', 'value': 'B203'},
        {'label': 'Nb de pro', 'value': 'total_pro'},
    ]
             , style={"width" : "80%"}
), dbc.Row([dcc.Graph(id='scoreselectab3')])]))




@app.callback(
    Output('scoreselectab3', 'figure'),
    [dash.dependencies.Input('scoretab3', 'value')])
def getmap (value) :
    df, jsonzdv=functions2.iris_by_zdv(df_poly, full_base)
    with open('multi.json') as json_file:
        jsonzdv = json.load(json_file)
    print(jsonzdv['features'][0]['properties'].keys())

    fig=go.Figure(go.Choroplethmapbox(geojson=jsonzdv, locations=df.index,
                                  z=df[value], featureidkey = 'properties.ZDV',
                                  colorscale="Viridis",
                                  marker_opacity=0.5, marker_line_width=0))

    fig.update_layout(mapbox_style="carto-positron",
                      mapbox_zoom=zoom, mapbox_center={"lat": lat, "lon": lon})
    fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
    fig.update_layout(clickmode='event+select')
    fig.update_layout(transition_duration=500)
    fig.show()
    return fig