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
access the map's html, without saving the file #781
Comments
I was wondering this myself as well. I think I found out how, by following the parent classes from |
Hi Frank. Thanks for digging into this. What I am trying to do is to be able to make changes to the map's HTML, but still display it so that it will show up in the notebook when it's exported as HTML. When I use iPython like so, The resulting map is not fully embedded/portable in the HTML notebook (it can't be sent to colleagues). So basically, is there a way to be able to make changes to the map's HTML, but still have it fully embedded in the notebook when it's exported as HTML? Sincerely, |
Hi, I am trying to use Folium in a web application and had a similar issue (I don't use jupyter). m = folium.Map()
iframe = m._repr_html_() and then, I guess
|
@fitoprincipe That will display the map with base64 encoding, which is great, but I am trying to make adjustments ("hacks") to the HTML string first, and then have it get rendered with base64 encoding. So for example, as @Conengmo suggested, if I wanted to force a heat map to stay on top of a choropleth, I could append some HTML to the main HTML that Folium creates, as follows:
The question now is how to display this new map, with base64 encoding, so that the map is nice and portable. I've tried converting my altered HTML to base64, prior to displaying it by using,
But that just shows a blank page. |
I tested two ways to do this with this example map:
A dirty way to do it is to replicate the
A probably better way is to make a class that inherits from Branca's
|
I found a much easier way in #370:
|
I am following along, shouldn't style go in head tag? like style_statement = '<style>.leaflet-control{color:#00FF00}</style>'
m.get_root().header.add_child(folium.Element(style_statement))
m |
@Conengmo Frank this is fantastic! The "dirty" way you described allows me to do everything I need. Specifically I am hacking two things:
I realise that this is heavy handed, but it works. Importantly, when exporting the notebook as HTML, the maps still need to be working when I send the file to someone else. Thanks to your help, this seems to be working consistently in Firefox with maps that are ~3MB in size. In Chrome, the maps only show up if they are very basic (like the test example above). I'm sure there is an explanation for that though, which I will investigate. I am using Folium maps to analyze how census data relates to specific schools. I think that is important work, and you have helped to make it possible. Thanks again, |
Glad to help Allen. By the way, your second point is something I encountered as well. I made a PR for it (#772) so maybe we'll see it in a next version. @fitoprincipe you're right, it should be in header. Thanks for the learning. |
Maybe we should document that somewhere... |
Maybe I am asking a quite preliminary question, but how can I show this on a website, such as Django? |
You mean the entire map? If you render the
I once made Flask app that just returns the html, I believe it was something like this.
Alternatively, you can try the
|
Thank you. Will try Jupyter Notebooks one. |
This did the trick for me, returning the HTML as string. Awesome! |
I have exported the Folium map to html. Now I want to update the map - like adding another featuregroup or markers and save the changes to the same html file. Requesting the members to suggest how to achieve this. Thanks. |
Hi guys,
Hopefully an easy one. I'm making a few changes to the html once the map is saved to a file. Is there a way to access the html directly, without using m.save()?
The text was updated successfully, but these errors were encountered: