Moving object on map [streamlit-folium]

:wave: streamlit fans,

I have what I believe is a basic use case. I have one (for the time being) object that is moving (could be a car … mine is flying).
I would like to plot its position on a map (I am currently using streamlit-folium but I could use whatever other component)
I have a loop modifying the position of the marker (object) … but it does not move. If I move st_data = st_folium(m, width=800, height=500) inside the loop it’s like plotting different map for each iteration (with the marker moving) but that is very slow (and I dont want multiple map)

I must be missing something :slight_smile:

Thanks for your help (the code is here GitHub - galleon/flight-planning)

no map aficionados here :sob:

OR, you just happened to post this during the Snowflake Summit, and employees were less available to answer questions :slight_smile:

I’m not sure this is a great use case for Folium, as you necessarily are going to have to re-draw the map (if I’m understanding correctly). Folium only takes in a static dataset, not a websocket or similar, so there’s no way to tell the map that new data arrived but not to re-draw the scene.

Best,
Randy

Hi Randy

Hope you had a nice time with your colleagues :slight_smile:
There is may be a go in between we can imagine to have some layers with static data (no nee to redraw them) and some with only the moving object which need to be redrawn.

Or may be the best solution is to wait for ipywidgets to be available in Streamlit and use ipyleaflet that should enable bi directional communication.

Any advice?

Thanks
Guillaume

PS: While waiting what about redrawing everything at each iteration. Can it be a temporary solution ?

I’m sure that’s possible with leaflet directly, but not sure that Folium supports this either.

Yes, I would start here. To animate it, you could index into a list, always keeping the 0 element, then incrementally moving the counter up.

There are leaflet plugins like GitHub - ATran31/Leaflet-GeoSSE: Leaflet plugin to handle real-time data updates using server sent events. or GitHub - perliedman/leaflet-realtime: Put realtime data on a Leaflet map to update maps with streaming/realtime data. One of those would need to be supported by folium, or maybe streamlit-folium could use one of those plugins to hook into the streamlit websocket.