Skip to content

Suppress IPython warning in show()#168

Open
bnaul wants to merge 1 commit intomapbox:masterfrom
bnaul:patch-2
Open

Suppress IPython warning in show()#168
bnaul wants to merge 1 commit intomapbox:masterfrom
bnaul:patch-2

Conversation

@bnaul
Copy link
Contributor

@bnaul bnaul commented Sep 5, 2019

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 bnaul changed the title Use IPython.display.IFrame in show() Suppress IPython warning in show() Sep 9, 2019
@bnaul
Copy link
Contributor Author

bnaul commented Sep 9, 2019

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
Copy link
Contributor

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 -

from IPython.core.display import HTML, display

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

@bnaul
Copy link
Contributor Author

bnaul commented Sep 10, 2019

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
Copy link
Contributor

ryanbaumann commented Sep 11, 2019

Thanks for digging @bnaul . Mapboxgl-Jupyter uses the srcdoc HTML attribute here as part of the as_iframe function -

def as_iframe(self, html_data):

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.

@buzzCraft buzzCraft mentioned this pull request Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants