-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
How to use folium with iPython / Jupyter notebook #135
Comments
@themiurgo that is a long standing issue that we need to address! The latest version of the Jupyter/IPython Notebook renders the HTML by itself, no need for (I haven't test this though. That is what I gathered from other users and colleagues.) Maybe we should focus on making this object more "Jupyter friendly" and kill the On the other hand I do use
The honest answer is no. But we need to check how the HTML object is rendering on nbviewer before telling people to stop using it. I have a bunch of tests here and I will check this once I get to the office. |
@ocefpaf Great, thanks! I use exclusively |
is |
Sorry Andrea, but the docs are so far behind that documenting inline_map() |
@ocefpaf I understand. If it is of any help, I hacked my way around it. Here is a version that works for me andreabedini/folium@50ade07. |
I use this: https://gist.github.com/themiurgo/f136265bdce26fbff704 and the only problem I've had is that maps disappear on consecutive reconnections to the same notebook. |
@themiurgo With my version that works edit: but to be honest I have some issues with CSS ... |
Quite close to @themiurgo , here is my hack for this issue : I guess having the map in an iframe avoids interaction between jupyter's javascript and leaflet's. At last, I like the possibility to choose the size of the "figure" ; most notebook users are using this functionnality in |
Random comment, but yesterday I found https://github.com/sandialabs/toyplot, which "Integrates with Jupyter without any need for plugins, magics, etc." (from their docs). I tried and it really works automagically. Maybe we can get some ideas on how to implement a similar thing in folium. |
@themiurgo I had a look at toyplot (which is great btw) and they use SVG for rendering and JS for animation (see To sum up we need a method:
And we have three candidates:
I'll try to test the three and summarize the strength / weakness of each. Did I miss something ? |
Indeed. Their approach is beautiful, but I cannot see how to implement those ideas in folium.
Nope! That pretty sums what needs to be done. Thanks @BibMartin! Some thoughts:
Maybe we won't find the "best" solution that to fixes everything 100%. To be honest I think our bug is in the docs. We need to properly document what users should use depending on the map they are producing. |
I want to page @rgbkrk to the discussion here. Kyle, I'm honestly leaning towards recommending a move towards Plotly has built some really nice stuff purely on iframes. Is this the direction we should be moving, or should we keep leaning on the built-in notebook machinery? |
As far as I undestand it (now), the main question is: If yes
But
If no
But
I must confess I am quite afraid about interaction issues (see an illustration on https://github.com/BibMartin/folium/blob/master/examples/javascript%20interference%20example.ipynb) and debugging javascript makes me pain. So my personal answer would be no. But I've tryied to be fair in this pros and cons exercise ; please tell me otherwise. |
From a light skim and a glance through docs on this library, I'm noticing that there are problems with:
The first (CSS) can be handled ok using a shadow DOM (this will only work in Chrome currently unless you include the polyfill on other browsers). You can address both the CSS and JS issues by using an iframe that you create. You're probably already aware, but working within iframes has its tricky bits. I personally prefer to put the iframe on the document, then get a handle for the Does folium ever use the Jupyter/IPython comms interface to pass messages? There are several issues I'm interested in pushing hard on with current work:
/cc @jdfreder |
As of PR #190 all you need is to leave the map object as the last thing in the cell and the IPython/Jupyter HTML repr will take care of the rest. (See: http://nbviewer.ipython.org/github/ocefpaf/folium_notebooks/tree/master/) |
Getting Jupyter notebooks to display
|
They are. That is GitHub scrubbing off the JS for security reasons. Here is the same notebook you mentioned above on
No functionality is gone. And all JS Jypyter stuff on GitHub will suffer from that. There is nothing we can. |
My bad, thanks for the clarification @ocefpaf. I did look inside my |
No problem. Glad you are using |
As far as I know there are two approaches for using folium inside a notebook:
What is the preferred way?
Several bugs are associated to the first (a quick search listed #90 , #44 , #132 ). Is there any advantage in using the first approach over the second? I tried to look for an answer in the issue tracker but did not find any.
Is there a reason for keeping both these approaches?
The text was updated successfully, but these errors were encountered: