# Potential bug in plotly maps reset view with data change

**URL:** <https://community.plotly.com/t/potential-bug-in-plotly-maps-reset-view-with-data-change/88604>\
**Category:** Dash Python\
**Tags:** question, bug-reporter\
**Created:** [November 11, 2024, 10:06am UTC](https://community.plotly.com/t/potential-bug-in-plotly-maps-reset-view-with-data-change/88604 "2024-11-11T10:06:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![prwagner](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@prwagner](https://community.plotly.com/u/prwagner)\
**Post date:** [November 11, 2024, 10:06am UTC](https://community.plotly.com/t/potential-bug-in-plotly-maps-reset-view-with-data-change/88604/1 "2024-11-11T10:06:23Z")

</div>

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](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`.

```python
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)

```

---

<div class="post-metadata">

**Author:** ![prwagner](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@prwagner](https://community.plotly.com/u/prwagner)\
**Post date:** [November 25, 2024, 8:21am UTC](https://community.plotly.com/t/potential-bug-in-plotly-maps-reset-view-with-data-change/88604/2 "2024-11-25T08:21:15Z")

</div>

I attach a GIF of the MRE for further clarification (Thanks to [this post](https://community.plotly.com/t/tool-for-creating-gifs/76061) for linking the screen capture tool).  
 ![dash_bug](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/9/b/9b2df65754625caee7b1a6a86c8ea54933786ed5.gif)
