I have noticed a bug that might be related to https://community.plotly.com/t/reset-view-option-on-scatter-mapbox-is-stuck-on-old-data/46758 but I am raising it again here including a minimal reproducible example.
Problem description
The issue occurs when plotting data A on a map and zooming in on the data location, replacing the Figure with data B and corresponding location, and resetting the view (via double click or the resetView
modebar button). The expected behavior would be for the map to zoom in on data B, but the view is actually reset to the original data A.
Potential fix
What confuses me, is that data A should not be present in the session anymore, we are recreating the figure in dcc.Graph
after all - but the original view has to somehow remain in the session. My guess is that it is stored in dcc.Graph
, but I know too little about the underlying javascript implementation to dig deeper.
Thanks for your help and I attach the MRE below.
Minimal reproducible example
This uses python==3.12
, dash==2.18.2
, and plotly==5.24.1
.
from dash import Dash, dcc, html, Input, Output
import plotly.graph_objs as go
app = Dash(__name__)
app.layout = html.Div([
html.H4('Data source resetView issue'),
html.P("Select data source:"),
dcc.RadioItems(
id='data-source',
options=["data A", "data B"],
value="data A",
inline=True
),
dcc.Graph(id="graph"),
])
@app.callback(
Output("graph", "figure"),
Input("data-source", "value"))
def display_choropleth(data_source):
fig = go.Figure()
if data_source == 'data A':
data = dict(lat=[0], lon=[0])
center = dict(lat=0, lon=0)
else:
data = dict(lat=[40], lon=[0])
center = dict(lat=40, lon=0)
fig.add_trace(go.Scattermap(**data, mode='markers'))
fig.update_layout(map=dict(center=center, zoom=12))
return fig
app.run_server(debug=True)