streamlit-folium icon indicating copy to clipboard operation
streamlit-folium copied to clipboard

st_folium() autorefresh issue

Open daniyal-d opened this issue 3 years ago • 5 comments
trafficstars

I recently switched from using folium_static() to st_folium() but I have an issue with its autorefresh. Whenever the folium map is interacted with, the website refreshes from the very top of the page. My project involves scraping data from a website, so anytime the page refreshes, all the code runs again. This makes it virtually impossible to interact with the map. Below is the streamlit app and code

Code (code for map beings on line 248): https://github.com/daniyal-d/COVID-19-Tracker-Web-App/blob/main/coronavirus_web_app.py Streamlit app (using st_folium): https://daniyal-d-covid-19-tracker-web-app-coronavirus-web-app-fah46j.streamlitapp.com/

I am unsure if this is an issue with my code or the function. Either way, using folium_static() doesn't lead to any issues. If this problem can't be solved, would you be able to not depreciate 'folium_static()` as the app uses it?

Thank you

daniyal-d avatar Jul 07 '22 07:07 daniyal-d

If this problem can't be solved, would you be able to not depreciate 'folium_static()` as the app uses it?

Yeah, for the time being, there isn't a firm date around the deprecation. But if I didn't put that I was planning to, no one would ever report their issues :)

So thanks for reporting, we'll take a look and see if we can figure out what the issue may be.

randyzwitch avatar Jul 08 '22 15:07 randyzwitch

@randyzwitch Alright thank you. For now I'm going to revert back to folium_static()

daniyal-d avatar Jul 10 '22 05:07 daniyal-d

Hello! Going to chime in here as well, as it also relates to me. Im using a folium plugin called HeatMap and get the same problem (page perma reloading the map).

ossings avatar Jul 14 '22 14:07 ossings

Thanks for reporting @ossings, this might be the same issue as #72, so hopefully when we solve that we'll solve yours as well.

randyzwitch avatar Jul 19 '22 13:07 randyzwitch

@daniyal-d Thanks for sharing this. In general, this is the expected behavior from streamlit widgets, and the general recommendation is that if you have slow functions that you'd like not to run every time, you should use st.experimental_memo to cache them.

I'm not sure that this would do exactly what you want, but something like this might well solve your problem. https://github.com/daniyal-d/COVID-19-Tracker-Web-App/compare/main...blackary:COVID-19-Tracker-Web-App:patch-1

Now, if you or @ossings are seeing the issue reported in #72 where folium keeps rerendering, that seems like a different (though possibly related) issue. But, having a widget cause the page to rerender when it changes is the typical behavior of a streamlit widget.

blackary avatar Jul 19 '22 16:07 blackary

@randyzwitch I'm having same issue after switching to st.folium (constantly rendering when I interact with the map) I had to revert back to folium_static which performs with no issue. no widgets used / no st.col or st.empty used. i'm researching best practices for filtering a folium map within streamlit app. i.e. if a user has an input box filter both map and data frame. no solutions yet. 😞

limowreck00 avatar Sep 30 '22 12:09 limowreck00

I'm having this same issue with streamlit folium too. I know that is the usual pattern for all components to re-run the whole page whenever its state changes, and thats at the core of how streamlit works. But for the case of moving around the map, zooming in, zooming out, this folium component should be configurable to prevent those actions from re-running the page if desired.

ashleysommer avatar Oct 28 '22 06:10 ashleysommer

I also have this same issue with streamlit folium. I have 2000 meteorological stations. Everytime I drag the map, it will cost about 4~5 seconds to response. Any suggestion how to improve the performance?

20231015182548.webm

kongdd avatar Oct 15 '23 09:10 kongdd

@kongdd there have been several performance improvements merged in recently -- are you using the latest version of the library?

Also, if you don't need to interact with all of the different changes on the map, you might try changing the returned_objects argument to only those that you want to affect your app.

blackary avatar Oct 16 '23 14:10 blackary