|
20 | 20 | import flask |
21 | 21 |
|
22 | 22 | from pkg_resources import get_distribution, parse_version |
23 | | -from plotly.offline import get_plotlyjs_version |
24 | 23 |
|
25 | 24 | from dash import dcc |
26 | 25 | from dash import html |
@@ -342,6 +341,8 @@ class Dash: |
342 | 341 | if not added previously. |
343 | 342 | """ |
344 | 343 |
|
| 344 | + _plotlyjs_url: str |
| 345 | + |
345 | 346 | def __init__( # pylint: disable=too-many-statements |
346 | 347 | self, |
347 | 348 | name=None, |
@@ -589,6 +590,8 @@ def _handle_error(_): |
589 | 590 | _get_app.APP = self |
590 | 591 | self.enable_pages() |
591 | 592 |
|
| 593 | + self._setup_plotlyjs() |
| 594 | + |
592 | 595 | def _add_url(self, name, view_func, methods=("GET",)): |
593 | 596 | full_name = self.config.routes_pathname_prefix + name |
594 | 597 |
|
@@ -620,6 +623,25 @@ def _setup_routes(self): |
620 | 623 | # catch-all for front-end routes, used by dcc.Location |
621 | 624 | self._add_url("<path:path>", self.index) |
622 | 625 |
|
| 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 | + |
623 | 645 | @property |
624 | 646 | def layout(self): |
625 | 647 | return self._layout |
@@ -706,9 +728,7 @@ def _config(self): |
706 | 728 | "serve_locally": self.config.serve_locally, |
707 | 729 | } |
708 | 730 | 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 |
712 | 732 | if self._dev_tools.hot_reload: |
713 | 733 | config["hot_reload"] = { |
714 | 734 | # convert from seconds to msec as used by js `setInterval` |
|
0 commit comments