Hi,
I create an initial empty scattermapbox in the following way:
initialize figure
fig = px.scatter_mapbox(zoom= 7, height=1000, center = {‘lat’: 52.6, ‘lon’:5})
fig.update_layout(mapbox_style=“open-street-map”, margin=dict(l=0,r=0,b=0,t=0), paper_bgcolor=“Black”)
I then store it in a Div:
html.Div(id = ‘Graph_container’, children = dcc.Graph(id=‘mapbox’,figure= fig))
Next I create dynamically some objects that alter this figure through a callback:
@app.callback(
Output(component_id = ‘mapbox’, component_property = ‘figure’),
Input(component_id = {‘type’: ‘data_shorelinedevelop’, ‘index’: ALL}, component_property = ‘value’),
)
def update_figure(value):
if len(value) > 0:
value = value[0]
print(value)
if value == 1:
fig = px.scatter_mapbox(
df, lat=“Intersect_lat”,
lon=“Intersect_lon”,
hover_name=“transect_id”,
hover_data=[“country_name”, “changerate”],
labels = {‘country_name’ : ‘Country’, ‘Intersect_lat’: ‘Latitude’, ‘Intersect_lon’: ‘Longitude’},
color_discrete_sequence=[“black”], zoom= 7, height=1000, center = {‘lat’: 52.6, ‘lon’:5})
fig.update_layout(mapbox_style=“open-street-map”, margin=dict(l=0,r=0,b=0,t=0), paper_bgcolor=“Black”)
fig.update_traces(marker={‘size’: 5})
return fig
if value == 2:
fig = px.scatter_mapbox(zoom= 7, height=1000, center = {'lat': 40, 'lon':5})
fig.update_layout(mapbox_style="open-street-map", margin=dict(l=0,r=0,b=0,t=0), paper_bgcolor="Black")
return fig
else:
raise PreventUpdate
However this Callback only is triggered the first time I click on the input it and when value equals 1 only the hover shows and the markers do not. When I change the output to the id of the graph container and I return a dcc.graph it works perfectly fine. Anyone knows if it is also possible to return the figure?
Regards,
Dante