python-visualization / folium

Python Data. Leaflet.js Maps.
https://python-visualization.github.io/folium/
MIT License
6.87k stars 2.22k forks source link

Update/refresh an already rendered map? #906

Open deeplook opened 6 years ago

deeplook commented 6 years ago

This is more of a feature request, as I don't think this already works. But it would be very useful to have the possibility to render a map, say with some GeoJSON content, and re-render (refresh) the same map (in a Jupyter notebook cell, say) with some other or additional content, later. It would also allow for some kind of simple animations. Or are there any other ways to get this?

Conengmo commented 6 years ago

You're right that folium cannot dynamically update data, as in you cannot send data from Python to the already rendered map. Unless someone has a good idea for how to sensibly do this, this is out of the scope of folium.

You can of course update your Python data and then again render the map. But that wouldn't be fast enough for animations I suppose. Haven't tried this.

Have you looked into the plugins that can do animations? There is a plugin for timestamped geojsons that might work best for you. Example for that is here, check it out.

There's also an example for the timeslider choropleth plugin. And maybe have a look at the heatmap with time plugin.

deeplook commented 6 years ago

@Conengmo That's cool! I've played a bit with the TimestampedGeoJson example. If I import it from folium.plugins it works fine and shows the playing widgets on the map. If I copy the code locally and import TimestampedGeoJson from it I don't get these widgets, though. Any ideas, why? I wanted to do this as a first step in trying to come up with a StreamingGeoJson example in the spirit of this one for node.js.

Conengmo commented 6 years ago

I'm not sure what you mean. Maybe you can share a link to a branch, gist of notebook?

deeplook commented 6 years ago

I will likely use ipyleaflet instead as that provides very simple features to modify map content dynamically. See https://youtu.be/NBZBjEjN-rU?t=2h20m15s

Conengmo commented 6 years ago

Good call. I'll close the issue then.

danwild commented 3 years ago

@Conengmo

IMO not having this feature is a pretty substantial blocker to building more complex/interactive applications with Folium (particularly with proliferation of dashboarding tools like Voilà, Dash, Streamlit, Panel, etc. that could be making use of Folium).

Having to recreate an entirely new map just to change update a fraction of existing data/layers is a huge overhead (e.g. as I'm understanding it - currently if you have 10 layers and want to arbitrarily modify 1x layer, you need to recreate the map and all 10x layers).

I note that PyDeck, which serves a similar role to Folium, appears to have implemented this, so perhaps some ideas there:

https://pydeck.gl/deck.html#pydeck.bindings.deck.Deck.update

Conengmo commented 3 years ago

Hi Dan, folium is maintained by volunteers. Having new or better functionality is entirely dependent on whether someone turns up to make the effort. If you or someone else wants to look into this you are welcome to do so.

I agree with what you are saying. It’s more a question of what needs to change to make it possible, and how to do that in a clean and sane way. I don’t know the answer yet to both those questions. Someone would have to investigate.

danwild commented 3 years ago

Yep @Conengmo I 100% understand these things don’t just happen by themselves, and a PR would have been much more helpful than a comment 😅

I guess at a minimum I’m suggesting the issue should be reopened to acknowledge that this feature would indeed be useful, and that help is invited.

Bonus points if those familiar with Folium code base could provide any tips on where a new contributor might get started.

deeplook commented 3 years ago

It could be hard for Folium to provide such features. Depending on what exactly is needed I would recommend considering Ipyleaflet, too. It is way more dynamic and better suited for more complex, say analysis, contexts, while Folium seems to target better static simple use cases on websites.

pstatonwx commented 2 years ago

Any update/progress on this?