From 1d9f17a8a8f9fe41935c255a2b5eadeb8fafb117 Mon Sep 17 00:00:00 2001 From: Martha Cryan Date: Wed, 11 Sep 2024 21:34:31 +0200 Subject: [PATCH 1/8] Remove requirejs --- .../plotly/plotly/io/_base_renderers.py | 45 +++---------------- packages/python/plotly/plotly/io/_html.py | 32 ++----------- .../plotly/tests/test_io/test_renderers.py | 11 ----- 3 files changed, 8 insertions(+), 80 deletions(-) diff --git a/packages/python/plotly/plotly/io/_base_renderers.py b/packages/python/plotly/plotly/io/_base_renderers.py index 5a75f010633..6c2912457a1 100644 --- a/packages/python/plotly/plotly/io/_base_renderers.py +++ b/packages/python/plotly/plotly/io/_base_renderers.py @@ -249,7 +249,6 @@ def __init__( self, connected=False, full_html=False, - requirejs=True, global_init=False, config=None, auto_play=False, @@ -261,7 +260,6 @@ def __init__( self.auto_play = auto_play self.connected = connected self.global_init = global_init - self.requirejs = requirejs self.full_html = full_html self.animation_opts = animation_opts self.post_script = post_script @@ -274,28 +272,14 @@ def activate(self): cls=self.__class__.__name__ ) ) - - if not self.requirejs: - raise ValueError("global_init is only supported with requirejs=True") - + print("self.connected: ", self.connected) if self.connected: - # Connected so we configure requirejs with the plotly CDN script = """\ + """.format( win_config=_window_plotly_config, mathjax_config=_mathjax_config, @@ -309,15 +293,7 @@ def activate(self): """.format( script=get_plotlyjs(), @@ -331,10 +307,7 @@ def to_mimebundle(self, fig_dict): from plotly.io import to_html - if self.requirejs: - include_plotlyjs = "require" - include_mathjax = False - elif self.connected: + if self.connected: include_plotlyjs = "cdn" include_mathjax = "cdn" else: @@ -416,7 +389,6 @@ def __init__( super(NotebookRenderer, self).__init__( connected=connected, full_html=False, - requirejs=True, global_init=True, config=config, auto_play=auto_play, @@ -444,7 +416,6 @@ def __init__( super(KaggleRenderer, self).__init__( connected=True, full_html=False, - requirejs=True, global_init=True, config=config, auto_play=auto_play, @@ -472,7 +443,6 @@ def __init__( super(AzureRenderer, self).__init__( connected=True, full_html=False, - requirejs=True, global_init=True, config=config, auto_play=auto_play, @@ -497,7 +467,6 @@ def __init__( super(ColabRenderer, self).__init__( connected=True, full_html=True, - requirejs=False, global_init=False, config=config, auto_play=auto_play, @@ -832,7 +801,6 @@ def __init__( super(SphinxGalleryHtmlRenderer, self).__init__( connected=connected, full_html=False, - requirejs=False, global_init=False, config=config, auto_play=auto_play, @@ -844,10 +812,7 @@ def to_mimebundle(self, fig_dict): from plotly.io import to_html - if self.requirejs: - include_plotlyjs = "require" - include_mathjax = False - elif self.connected: + if self.connected: include_plotlyjs = "cdn" include_mathjax = "cdn" else: diff --git a/packages/python/plotly/plotly/io/_html.py b/packages/python/plotly/plotly/io/_html.py index 981f414aedf..fe136518cc9 100644 --- a/packages/python/plotly/plotly/io/_html.py +++ b/packages/python/plotly/plotly/io/_html.py @@ -67,12 +67,6 @@ def to_html( plotly.min.js bundle that is assumed to reside in the same directory as the HTML file. - If 'require', Plotly.js is loaded using require.js. This option - assumes that require.js is globally available and that it has been - globally configured to know how to find Plotly.js as 'plotly'. - This option is not advised when full_html=True as it will result - in a non-functional html file. - If a string that ends in '.js', a script tag is included that references the specified path. This approach can be used to point the resulting HTML file to an alternative CDN or local bundle. @@ -254,20 +248,10 @@ def to_html( if isinstance(include_plotlyjs, str): include_plotlyjs = include_plotlyjs.lower() - # Start/end of requirejs block (if any) - require_start = "" - require_end = "" - # Init and load load_plotlyjs = "" - # Init plotlyjs. This block needs to run before plotly.js is loaded in - # order for MathJax configuration to work properly - if include_plotlyjs == "require": - require_start = 'require(["plotly"], function(Plotly) {' - require_end = "});" - - elif include_plotlyjs == "cdn": + if include_plotlyjs == "cdn": load_plotlyjs = """\ {win_config} \ @@ -343,10 +327,8 @@ def to_html(
\ \ """.format( mathjax_script=mathjax_script, @@ -355,9 +337,7 @@ def to_html( width=div_width, height=div_height, base_url_line=base_url_line, - require_start=require_start, script=script, - require_end=require_end, ).strip() if full_html: @@ -433,12 +413,6 @@ def write_html( directory because the plotly.js source code will be included only once per output directory, rather than once per output file. - If 'require', Plotly.js is loaded using require.js. This option - assumes that require.js is globally available and that it has been - globally configured to know how to find Plotly.js as 'plotly'. - This option is not advised when full_html=True as it will result - in a non-functional html file. - If a string that ends in '.js', a script tag is included that references the specified path. This approach can be used to point the resulting HTML file to an alternative CDN or local bundle. diff --git a/packages/python/plotly/plotly/tests/test_io/test_renderers.py b/packages/python/plotly/plotly/tests/test_io/test_renderers.py index 63305cc719f..89499028966 100644 --- a/packages/python/plotly/plotly/tests/test_io/test_renderers.py +++ b/packages/python/plotly/plotly/tests/test_io/test_renderers.py @@ -145,14 +145,6 @@ def assert_offline(html): assert get_plotlyjs() in html -def assert_requirejs(html): - assert 'require(["plotly"]' in html - - -def assert_not_requirejs(html): - assert 'require(["plotly"]' not in html - - def test_colab_renderer_show(fig1): pio.renderers.default = "colab" @@ -170,7 +162,6 @@ def test_colab_renderer_show(fig1): html = mock_arg1["text/html"] assert_full_html(html) assert_html_renderer_connected(html) - assert_not_requirejs(html) # check kwargs mock_kwargs = mock_call_args[1] @@ -213,7 +204,6 @@ def test_notebook_connected_show(fig1, name, connected): # Check html display contents bundle_html = mock_arg1["text/html"] assert_not_full_html(bundle_html) - assert_requirejs(bundle_html) # check kwargs mock_kwargs = mock_call_args[1] @@ -275,7 +265,6 @@ def open_url(url, new=0, autoraise=True): html = response.content.decode("utf8") assert_full_html(html) assert_offline(html) - assert_not_requirejs(html) # Validation From 34ccc60bfab266fbadd7aacbf112b93e3418c8a4 Mon Sep 17 00:00:00 2001 From: Martha Cryan Date: Wed, 11 Sep 2024 21:38:13 +0200 Subject: [PATCH 2/8] Remove comments describing requirejs as an option --- packages/python/plotly/plotly/basedatatypes.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index 21b4cb1f312..1fd6adf1bbf 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -3534,12 +3534,6 @@ def to_html(self, *args, **kwargs): plotly.min.js bundle that is assumed to reside in the same directory as the HTML file. - If 'require', Plotly.js is loaded using require.js. This option - assumes that require.js is globally available and that it has been - globally configured to know how to find Plotly.js as 'plotly'. - This option is not advised when full_html=True as it will result - in a non-functional html file. - If a string that ends in '.js', a script tag is included that references the specified path. This approach can be used to point the resulting HTML file to an alternative CDN or local bundle. @@ -3643,12 +3637,6 @@ def write_html(self, *args, **kwargs): directory because the plotly.js source code will be included only once per output directory, rather than once per output file. - If 'require', Plotly.js is loaded using require.js. This option - assumes that require.js is globally available and that it has been - globally configured to know how to find Plotly.js as 'plotly'. - This option is not advised when full_html=True as it will result - in a non-functional html file. - If a string that ends in '.js', a script tag is included that references the specified path. This approach can be used to point the resulting HTML file to an alternative CDN or local bundle. From ced2c8b9a0536b20244afde176de5fef38d47afe Mon Sep 17 00:00:00 2001 From: Martha Cryan Date: Wed, 11 Sep 2024 21:39:55 +0200 Subject: [PATCH 3/8] Remove print statement --- packages/python/plotly/plotly/io/_base_renderers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/io/_base_renderers.py b/packages/python/plotly/plotly/io/_base_renderers.py index 6c2912457a1..c204775ad94 100644 --- a/packages/python/plotly/plotly/io/_base_renderers.py +++ b/packages/python/plotly/plotly/io/_base_renderers.py @@ -272,7 +272,7 @@ def activate(self): cls=self.__class__.__name__ ) ) - print("self.connected: ", self.connected) + if self.connected: script = """\ ' '
" + " " ) if "text/html" in bundle: str_bundle = bundle["text/html"] From c5a29937fbbd3dffbe66c8d668897c7ee1f1435a Mon Sep 17 00:00:00 2001 From: Martha Cryan Date: Thu, 12 Sep 2024 16:03:20 +0200 Subject: [PATCH 5/8] Add changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3200a0d9562..b35d7b815ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Fixed a bug in integer validation of arrays that threw an error when an array contained a mix of strings and integers. +- Fixed a bug in JupyterLab >= 4 and Jupyter Notebook >= 7 that caused latex to not render in plotly charts. + +- Removed require.js from the generated javascript in plotly charts. + ## [5.23.0] - 2024-07-23 ### Updated From c3fc5c8813d0bdd305d69cc79cd9864cec6ee6f5 Mon Sep 17 00:00:00 2001 From: Martha Cryan Date: Thu, 12 Sep 2024 20:27:27 +0200 Subject: [PATCH 6/8] Update to the module type and native es6 import --- packages/python/plotly/plotly/io/_base_renderers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/io/_base_renderers.py b/packages/python/plotly/plotly/io/_base_renderers.py index c204775ad94..aa80e2cb348 100644 --- a/packages/python/plotly/plotly/io/_base_renderers.py +++ b/packages/python/plotly/plotly/io/_base_renderers.py @@ -279,7 +279,7 @@ def activate(self): {win_config} {mathjax_config} - + """.format( win_config=_window_plotly_config, mathjax_config=_mathjax_config, From 26c4443b1a2efc83a5af3efd179c68f5e13cdfad Mon Sep 17 00:00:00 2001 From: Martha Cryan Date: Wed, 18 Sep 2024 21:38:17 +0200 Subject: [PATCH 7/8] Update CHANGELOG.md Co-authored-by: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b35d7b815ac..c1b22c89af6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Fixed a bug in JupyterLab >= 4 and Jupyter Notebook >= 7 that caused latex to not render in plotly charts. -- Removed require.js from the generated javascript in plotly charts. +- Use modern [native ES6 import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) to load plotly.js bundle instead of requirejs which is [no longer under active development](https://github.com/requirejs/r.js/compare/2.3.6...2.3.7) ## [5.23.0] - 2024-07-23 From fa4bba0608ed401adc7885b8219876e1d8c6ba88 Mon Sep 17 00:00:00 2001 From: Martha Cryan Date: Mon, 23 Sep 2024 17:09:24 +0200 Subject: [PATCH 8/8] Update loading of full plotly.js library to use script module type --- packages/python/plotly/plotly/io/_base_renderers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/io/_base_renderers.py b/packages/python/plotly/plotly/io/_base_renderers.py index aa80e2cb348..535b2e789e2 100644 --- a/packages/python/plotly/plotly/io/_base_renderers.py +++ b/packages/python/plotly/plotly/io/_base_renderers.py @@ -293,8 +293,8 @@ def activate(self): + """.format( script=get_plotlyjs(), win_config=_window_plotly_config,