Skip to content

Conversation

@yzhaoinuw
Copy link
Contributor

This pull request aims to address the following bug.

Describe the bug 🖍️
When calling FigureResampler.show_dash() without specifying mode, the method raises TypeError: argument of type 'NoneType' is not iterable. Full error message is

TypeError                                 Traceback (most recent call last)
File c:\users\yzhao\python_projects\plotly-resampler\tests\test_show_dash.py:19
     16 fig = FigureResampler(go.Figure())
     17 fig.add_trace(go.Scattergl(), hf_x=x, hf_y=y)
---> 19 fig.show_dash(config={"scrollZoom": True})  # mode defaults to None

File ~\python_projects\plotly-resampler\plotly_resampler\figure_resampler\figure_resampler.py:610, in FigureResampler.show_dash(self, mode, config, init_dash_kwargs, graph_properties, **kwargs)
    608 # 2. Run the app
    609 height_param = "height" if mode == "inline_persistent" else "jupyter_height"
--> 610 if "inline" in mode and height_param not in kwargs:
    611     # If app height is not specified -> re-use figure height for inline dash app
    612     #  Note: default layout height is 450 (whereas default app height is 650)
    613     #  See: https://plotly.com/python/reference/layout/#layout-height
    614     fig_height = self.layout.height if self.layout.height is not None else 450
    615     kwargs[height_param] = fig_height + 18

TypeError: argument of type 'NoneType' is not iterable

Reproducing the bug 🔍

import numpy as np
import plotly.graph_objects as go
from plotly_resampler import FigureResampler


x = np.arange(100)
y = np.sin(x)

fig = FigureResampler(go.Figure())
fig.add_trace(go.Scattergl(), hf_x=x, hf_y=y)

fig.show_dash(config={"scrollZoom": True})  # mode defaults to None

Expected behavior 🔧
The figure opens in "external" mode, according to the show_dash docstring.

Environment information: (please complete the following information)

  • OS: Windows 11
  • Python environment:
    • Python version: 3.12
    • plotly-resampler environment: e.g.: Dash web app (Chrome)
  • plotly-resampler version: 0.11.0

Additional context
The cause of the error is in the line if "inline" in mode and height_param not in kwargs: , which doesn't work when mode defaults to None but is regarded as a string here. We can fix this by setting mode to "external" before this line.

1. Fix the TypeError one encounters when using FigureResampler's
   show_dash method with the default mode, which is None.
2. Add test.
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.

1 participant