Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map reloading entirely upon changing data #3

Open
HugoAndre276 opened this issue Mar 21, 2024 · 1 comment
Open

Map reloading entirely upon changing data #3

HugoAndre276 opened this issue Mar 21, 2024 · 1 comment

Comments

@HugoAndre276
Copy link

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!

@reyemb
Copy link
Owner

reyemb commented Mar 28, 2024

Hoi Hugo,

Currently I cant take a look at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants