mapbox / mapboxgl-jupyter

Use Mapbox GL JS to visualize data in a Python Jupyter notebook
MIT License
661 stars 136 forks source link

Suppress IPython warning in `show()` #168

Open bnaul opened 5 years ago

bnaul commented 5 years ago

Not sure if this is only a problem in recent IPython versions but for me every plot is accompanied by:

/Users/brett/venvs/model/src/ipython/IPython/core/display.py:694: UserWarning: Consider using IPython.display.IFrame instead
  warnings.warn("Consider using IPython.display.IFrame instead")

Seems safe enough...?

bnaul commented 4 years ago

Just realized this wasn't actually as simple as I thought, the way Mapbox wants the iframe to look seems incompatible with how the IPython function produces it. Changed to just suppress the warning unless someone has a better idea (@ryanbaumann ?)

ryanbaumann commented 4 years ago

In general I don't think we should support suppressing warnings. Instead let's figure out why the warning is thrown and if there is a workaround or upgrade to make.

Here's the code we use to display an HTML element in Ipython - https://github.com/mapbox/mapboxgl-jupyter/blob/da6830828dbad62d348d5a05a877e54db9d633cd/mapboxgl/viz.py#L5

Here's the docs for Ipython display - https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html

bnaul commented 4 years ago

yeah, that was my first attempt but it didn't end up working.

the function that IPython is trying to force you to use is here: https://github.com/ipython/ipython/blob/56ea43f4378f4a87e3aec4cfae4dca26bb69c2ec/IPython/lib/display.py#L239-L273

it seems that mapbox expects a srcdoc attribute whereas ipython calls it src. since there's no way to override that behavior I'm not sure what to do...

ryanbaumann commented 4 years ago

Thanks for digging @bnaul . Mapboxgl-Jupyter uses the srcdoc HTML attribute here as part of the as_iframe function - https://github.com/mapbox/mapboxgl-jupyter/blob/da6830828dbad62d348d5a05a877e54db9d633cd/mapboxgl/viz.py#L244

We could take two approached - change the as_iframe function in Mapboxgl-Jupyter, or identify a fix upstream in ipython display. We used srcdoc in the iframe in order to inject an HTML source as a string into the iframe display, as opposed to referencing a remote source i.e. ./localfile.html.

We can reference folium to see what approach that SDK uses for loading a dynamic HTML component inline with a Notebook cell.