Black Lives Matter. Please consider donating to Black Girls Code today.
Dash Enterprise delivers an incredible 21x cost savings 💸Download the e-book!

Express px.scatter_mapbox - Possible to refresh data but maintain zoom and position?

Hello everyone.

I am using a px.scatter_mapbox object as part of a Dash dashboard. The map is set to refresh on changes to the input data. This causes the map to redraw with the original zoom level and position. Is there any way to capture the map’s current zoom and position so I can pass it to the new px object, so it looks like we are just updating the data, and not reset to the original zoom level? Would go.scattermapbox work any better for this application?

Thanks

I believe what you are looking for is the uirevision property (for details, see the documentation). To keep zoom, pan etc., set this property when you update the figure, i.e.

fig['layout']['uirevision'] = 'something'

Thanks for the quick reply Emil. I checked the documentation, but am still not clear on what the settings should be. If I wanted to preserve the location for example, what setting should I set for figure[‘layout’][‘uirevision’]?

Thanks again!

Set it to anything, e.g. ‘Hello’. The concept is that zoom etc. is only reset when the value changes, i.e. in your case set it to the same value, ‘Hello’, when you update the data.

Got it. Truly oustanding. Thanks so much! With this setting, the data points update, but the other map settings do not. I assume this should also be faster than the alternative (not using ‘uirevision’) at all?

Great! I am not sure about speed - that would depend on how it’s implemented under the hood. Depending on your data flow, the figure update might not even be a bottle neck, so as an initial guess i would assume that the performance is not impacted. But the only way to know for sure is testing :wink:

Yes, absolutely. I’ll try it out. Thanks again for the great replies!