streamlit-plotly-mapbox-events
streamlit-plotly-mapbox-events copied to clipboard
Map reloading entirely upon changing data
Hi it's me again :D This issue is closely related to this one as I believe it originates from streamlit-plotly-events.
The same kind of issue can be recreated with streamlit-plotly-mapbox-events :
import streamlit as st
import numpy as np
from streamlit_plotly_mapbox_events import plotly_mapbox_events
import plotly.express as px
np.random.seed(1312)
# Initialize zoom and center variables in session state
if "zoom" not in st.session_state:
st.session_state.zoom = 3
if "center" not in st.session_state:
st.session_state.center = {"lat": 0, "lon": 0}
x = np.linspace(-5, 5, 50) + np.random.normal(loc=0, scale=0.1, size=50)
y = np.linspace(-5, 5, 50) + np.random.normal(loc=0, scale=0.1, size=50)
a = st.number_input("Left crop", value=0)
b = st.number_input("Right crop", value=len(x))
fig = px.scatter_mapbox(lat=x[a:b], lon=y[a:b], mapbox_style="open-street-map", zoom=st.session_state.zoom, center=st.session_state.center)
# Plotly express version
st.plotly_chart(fig)
# Plotly events version
plotly_mapbox_events(fig)
# Update zoom and center values in session state
st.session_state.zoom = fig.layout.mapbox.zoom
st.session_state.center = fig.layout.mapbox.center
I don't know if I can realistically expect a smooth update of the map as with native plotly, but I'm hoping you can make it happen 🙏
Thank you once again!
Hoi Hugo,
Currently I cant take a look at this.