Skip to content

Commit 11388d2

Browse files
authored
Fix: Import JupyterDashPersistentInlineOutput only when needed (#349)
* 🔍 Fix: Import JupyterDashPersistentInlineOutput only when needed and update dependencies #348 * :see_no_evil fix: fix formatting * 🔍 fix tests + improve import error message
1 parent 5eaded3 commit 11388d2

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

plotly_resampler/figure_resampler/figure_resampler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
MinMaxLTTB,
2727
)
2828
from .figure_resampler_interface import AbstractFigureAggregator
29-
from .jupyter_dash_persistent_inline_output import JupyterDashPersistentInlineOutput
3029
from .utils import is_figure, is_fr
3130

3231
# Default arguments for the Figure overview
@@ -626,6 +625,10 @@ def show_dash(
626625
# function signatures are slightly different for the (Jupyter)Dash and the
627626
# JupyterDashInlinePersistent implementations
628627
if mode == "inline_persistent":
628+
from .jupyter_dash_persistent_inline_output import (
629+
JupyterDashPersistentInlineOutput,
630+
)
631+
629632
jpi = JupyterDashPersistentInlineOutput(self)
630633
jpi.run_app(app=app, **kwargs)
631634
else:

plotly_resampler/figure_resampler/jupyter_dash_persistent_inline_output.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
try:
1313
from IPython.display import HTML, display
1414
except ImportError:
15-
pass
15+
raise ImportError(
16+
"The `jupyter_dash_persistent_inline_output` requirements are not installed.\n"
17+
"Please install them with:\n"
18+
"pip install plotly_resampler[inline_persistent]"
19+
)
1620

17-
from dash._jupyter import JupyterDash, _jupyter_config, make_server, retry
21+
from dash._jupyter import JupyterDash, _jupyter_config, make_server
1822
from plotly.graph_objects import Figure
23+
from retrying import retry
1924

2025

2126
class JupyterDashPersistentInlineOutput:

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ tsdownsample = ">=0.1.3"
5555

5656
[tool.poetry.extras]
5757
# Optional dependencies
58-
inline_persistent = ["kaleido", "Flask-Cors"]
58+
inline_persistent = ["kaleido", "Flask-Cors", "ipython"]
5959

6060
[tool.poetry.dev-dependencies]
6161
pytest = "^7.2.0"

tests/test_figure_resampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ def test_manual_jupyterdashpersistentinline():
12791279

12801280
import dash
12811281

1282-
from plotly_resampler.figure_resampler.figure_resampler import (
1282+
from plotly_resampler.figure_resampler.jupyter_dash_persistent_inline_output import (
12831283
JupyterDashPersistentInlineOutput,
12841284
)
12851285

0 commit comments

Comments
 (0)