Skip to content

Commit 91f6c2c

Browse files
committed
Delay get plotlyjs version
1 parent 81d2c52 commit 91f6c2c

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

Diff for: components/dash-core-components/dash_core_components_base/__init__.py

-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import os as _os
33
import sys as _sys
44

5-
from plotly.offline import get_plotlyjs_version
6-
75
import dash as _dash
86

97
from ._imports_ import * # noqa: F401, F403, E402
@@ -124,12 +122,6 @@
124122
"namespace": "dash",
125123
"dynamic": True,
126124
},
127-
{
128-
"relative_package_path": "package_data/plotly.min.js",
129-
"external_url": f"https://cdn.plot.ly/plotly-{get_plotlyjs_version()}.min.js",
130-
"namespace": "plotly",
131-
"async": "eager",
132-
},
133125
{
134126
"relative_package_path": "dcc/async-plotlyjs.js",
135127
"external_url": (

Diff for: dash/dash.py

+24-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import flask
2121

2222
from pkg_resources import get_distribution, parse_version
23-
from plotly.offline import get_plotlyjs_version
2423

2524
from dash import dcc
2625
from dash import html
@@ -342,6 +341,8 @@ class Dash:
342341
if not added previously.
343342
"""
344343

344+
_plotlyjs_url: str
345+
345346
def __init__( # pylint: disable=too-many-statements
346347
self,
347348
name=None,
@@ -589,6 +590,8 @@ def _handle_error(_):
589590
_get_app.APP = self
590591
self.enable_pages()
591592

593+
self._setup_plotlyjs()
594+
592595
def _add_url(self, name, view_func, methods=("GET",)):
593596
full_name = self.config.routes_pathname_prefix + name
594597

@@ -620,6 +623,25 @@ def _setup_routes(self):
620623
# catch-all for front-end routes, used by dcc.Location
621624
self._add_url("<path:path>", self.index)
622625

626+
def _setup_plotlyjs(self):
627+
# pylint: disable=import-outside-toplevel
628+
from plotly.offline import get_plotlyjs_version
629+
630+
url = f"https://cdn.plot.ly/plotly-{get_plotlyjs_version()}.min.js"
631+
632+
# pylint: disable=protected-access
633+
dcc._js_dist.extend(
634+
[
635+
{
636+
"relative_package_path": "package_data/plotly.min.js",
637+
"external_url": url,
638+
"namespace": "plotly",
639+
"async": "eager",
640+
}
641+
]
642+
)
643+
self._plotlyjs_url = url
644+
623645
@property
624646
def layout(self):
625647
return self._layout
@@ -706,9 +728,7 @@ def _config(self):
706728
"serve_locally": self.config.serve_locally,
707729
}
708730
if not self.config.serve_locally:
709-
config[
710-
"plotlyjs_url"
711-
] = f"https://cdn.plot.ly/plotly-{get_plotlyjs_version()}.min.js"
731+
config["plotlyjs_url"] = self._plotlyjs_url
712732
if self._dev_tools.hot_reload:
713733
config["hot_reload"] = {
714734
# convert from seconds to msec as used by js `setInterval`

0 commit comments

Comments
 (0)