randyzwitch / streamlit-folium

Streamlit Component for rendering Folium maps
https://folium.streamlit.app/
MIT License
468 stars 176 forks source link

Compatibility with st.empty. For scalability of shape #141

Closed chm10 closed 10 months ago

chm10 commented 1 year ago

It would be nice to create a single container, a placeholder with st.empty, and make it compatible with st_folium. I did not see any documentation about how to reuse the same map and change the zoom-in and zoom-out. I used the st_folium to get the interaction, and after I zoomed in and changed the layer, I didn't know how to replace the folium.GeoJson. I have a lot of geojson code, so I need to filter and delete each interaction before making layers available for the end users.

I'm trying to reproduce this project from leaflet. leaftlet

Any insight could be helpful.

randyzwitch commented 1 year ago

This almost certainly needs to be done on the Streamlit side as part of the custom components framework. We aren't doing anything here to make it not work, nor do I have any idea what it would take to make it work. What do you think @blackary ?

chm10 commented 1 year ago

I made a turnaround to reconstruct this map. My approach to code this solution was using your component framework and getting the return of st_folium(m). With this output, I store the data into st.session_state use the st.rerun(), and load the map again with the new GeoJson. Thank you for the good work getting the coordinates of clicking and storing the label data without this resource, I cannot make this solution possible. But I have done this because I cannot store the state of st_folium into st.empty placeholder and cannot reuse this component. If this problem is from Streamlit or Folium, I will open an issue there too.

chm10 commented 1 year ago

Reproducing the leaflet project is possible and has this performance result. As the shape does not always load, we can make it possible to scale. I store some of the shapes for testing. The same result is almost impossible when loading all the shapes.

Animação

randyzwitch commented 1 year ago

If this problem is from Streamlit

Yes, this is almost certainly functionality that the core Streamlit library needs to provide. It's definitely not a Folium issue, and probably not a streamlit-foilum issue.