Skip to content

iframe renderer fails in JupyterLab #4033

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

Closed
naterush opened this issue Jan 22, 2023 · 1 comment · Fixed by #4036
Closed

iframe renderer fails in JupyterLab #4033

naterush opened this issue Jan 22, 2023 · 1 comment · Fixed by #4036

Comments

@naterush
Copy link

If you run the following code in a JupyterLab cell:

import plotly.express as px
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [3, 4, 5]})
fig = px.line(df, x='A', y='B')
fig.show(renderer="iframe")

You get the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[8], line 5
      3 df = pd.DataFrame({'A': [1, 2, 3], 'B': [3, 4, 5]})
      4 fig = px.line(df, x='A', y='B')
----> 5 fig.show(renderer="iframe")

File ~/temps/2023-01-22-1674410931/venv/lib/python3.9/site-packages/plotly/basedatatypes.py:3390, in BaseFigure.show(self, *args, **kwargs)
   3357 """
   3358 Show a figure using either the default renderer(s) or the renderer(s)
   3359 specified by the renderer argument
   (...)
   3386 None
   3387 """
   3388 import plotly.io as pio
-> 3390 return pio.show(self, *args, **kwargs)

File ~/temps/2023-01-22-1674410931/venv/lib/python3.9/site-packages/plotly/io/_renderers.py:388, in show(fig, renderer, validate, **kwargs)
    385 fig_dict = validate_coerce_fig_to_dict(fig, validate)
    387 # Mimetype renderers
--> 388 bundle = renderers._build_mime_bundle(fig_dict, renderers_string=renderer, **kwargs)
    389 if bundle:
    390     if not ipython_display:

File ~/temps/2023-01-22-1674410931/venv/lib/python3.9/site-packages/plotly/io/_renderers.py:296, in RenderersConfig._build_mime_bundle(self, fig_dict, renderers_string, **kwargs)
    293             if hasattr(renderer, k):
    294                 setattr(renderer, k, v)
--> 296         bundle.update(renderer.to_mimebundle(fig_dict))
    298 return bundle

File ~/temps/2023-01-22-1674410931/venv/lib/python3.9/site-packages/plotly/io/_base_renderers.py:570, in IFrameRenderer.to_mimebundle(self, fig_dict)
    567     iframe_height = str(525 + iframe_buffer) + "px"
    569 # Build filename using ipython cell number
--> 570 filename = self.build_filename()
    572 # Make directory for
    573 try:

File ~/temps/2023-01-22-1674410931/venv/lib/python3.9/site-packages/plotly/io/_base_renderers.py:613, in IFrameRenderer.build_filename(self)
    611 ip = IPython.get_ipython() if IPython else None
    612 if ip:
--> 613     cell_number = next(ip.history_manager.get_tail(1), (0, -1, ""))[1] + 1
    614 else:
    615     cell_number = 0

TypeError: 'list' object is not an iterator

If you remove renderer="iframe", this completes correctly.

Relevant versions pip list | grep -E 'pandas|jupyter|plotly':

jupyter_client           7.4.9
jupyter_core             5.1.3
jupyter-events           0.6.3
jupyter_server           2.1.0
jupyter_server_terminals 0.4.4
jupyterlab               3.5.2
jupyterlab-pygments      0.2.2
jupyterlab_server        2.19.0
pandas                   1.5.3
plotly                   5.12.0

I have verified this bug is reproducible on both Mac Safari and Mac Chrome.

Let me know if any other additional information is helpful!

@nicolaskruchten
Copy link
Contributor

Thanks for the clear bug report! I have a fix and will release it this week, as early as tomorrow :)

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 a pull request may close this issue.

2 participants