diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index 21b4cb1f312..54a78d08c25 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -3524,22 +3524,10 @@ def to_html(self, *args, **kwargs): is included in the output. HTML files generated with this option are fully self-contained and can be used offline. - If 'cdn', a script tag that references the plotly.js CDN is included - in the output. HTML files generated with this option are about 3MB - smaller than those generated with include_plotlyjs=True, but they - require an active internet connection in order to load the plotly.js - library. - If 'directory', a script tag is included that references an external 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. @@ -3624,12 +3612,6 @@ def write_html(self, *args, **kwargs): is included in the output. HTML files generated with this option are fully self-contained and can be used offline. - If 'cdn', a script tag that references the plotly.js CDN is included - in the output. HTML files generated with this option are about 3MB - smaller than those generated with include_plotlyjs=True, but they - require an active internet connection in order to load the plotly.js - library. - If 'directory', a script tag is included that references an external plotly.min.js bundle that is assumed to reside in the same directory as the HTML file. If `file` is a string to a local file @@ -3643,12 +3625,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. diff --git a/packages/python/plotly/plotly/io/_base_renderers.py b/packages/python/plotly/plotly/io/_base_renderers.py index 5a75f010633..7134fc08bb1 100644 --- a/packages/python/plotly/plotly/io/_base_renderers.py +++ b/packages/python/plotly/plotly/io/_base_renderers.py @@ -8,7 +8,6 @@ from plotly import utils, optional_imports from plotly.io import to_json, to_image, write_image, write_html from plotly.io._orca import ensure_server -from plotly.io._utils import plotly_cdn_url from plotly.offline.offline import _get_jconfig, get_plotlyjs from plotly.tools import return_figure_from_figure_or_data @@ -249,7 +248,6 @@ def __init__( self, connected=False, full_html=False, - requirejs=True, global_init=False, config=None, auto_play=False, @@ -261,7 +259,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 @@ -275,33 +272,6 @@ def activate(self): ) ) - if not self.requirejs: - raise ValueError("global_init is only supported with requirejs=True") - - if self.connected: - # Connected so we configure requirejs with the plotly CDN - script = """\ - - """.format( - win_config=_window_plotly_config, - mathjax_config=_mathjax_config, - plotly_cdn=plotly_cdn_url().rstrip(".js"), - ) - else: # If not connected then we embed a copy of the plotly.js # library in the notebook @@ -309,15 +279,7 @@ def activate(self): """.format( script=get_plotlyjs(), @@ -331,15 +293,8 @@ def to_mimebundle(self, fig_dict): from plotly.io import to_html - if self.requirejs: - include_plotlyjs = "require" - include_mathjax = False - elif self.connected: - include_plotlyjs = "cdn" - include_mathjax = "cdn" - else: - include_plotlyjs = True - include_mathjax = "cdn" + include_plotlyjs = True + include_mathjax = "cdn" # build post script post_script = [ @@ -416,7 +371,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 +398,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 +425,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 +449,6 @@ def __init__( super(ColabRenderer, self).__init__( connected=True, full_html=True, - requirejs=False, global_init=False, config=config, auto_play=auto_play, @@ -767,7 +718,7 @@ def __init__( auto_play=False, post_script=None, animation_opts=None, - include_plotlyjs="cdn", + include_plotlyjs=True, ): self.config = config @@ -832,7 +783,6 @@ def __init__( super(SphinxGalleryHtmlRenderer, self).__init__( connected=connected, full_html=False, - requirejs=False, global_init=False, config=config, auto_play=auto_play, @@ -844,15 +794,8 @@ def to_mimebundle(self, fig_dict): from plotly.io import to_html - if self.requirejs: - include_plotlyjs = "require" - include_mathjax = False - elif self.connected: - include_plotlyjs = "cdn" - include_mathjax = "cdn" - else: - include_plotlyjs = True - include_mathjax = "cdn" + include_plotlyjs = True + include_mathjax = "cdn" html = to_html( fig_dict, @@ -882,7 +825,7 @@ def render(self, fig_dict): filename_html = filename_root + ".html" filename_png = filename_root + ".png" figure = return_figure_from_figure_or_data(fig_dict, True) - _ = write_html(fig_dict, file=filename_html, include_plotlyjs="cdn") + _ = write_html(fig_dict, file=filename_html, include_plotlyjs=True) try: write_image(figure, filename_png) except (ValueError, ImportError): diff --git a/packages/python/plotly/plotly/io/_html.py b/packages/python/plotly/plotly/io/_html.py index 981f414aedf..65c4b1c60fe 100644 --- a/packages/python/plotly/plotly/io/_html.py +++ b/packages/python/plotly/plotly/io/_html.py @@ -3,7 +3,7 @@ import webbrowser from _plotly_utils.optional_imports import get_module -from plotly.io._utils import validate_coerce_fig_to_dict, plotly_cdn_url +from plotly.io._utils import validate_coerce_fig_to_dict from plotly.offline.offline import _get_jconfig, get_plotlyjs _json = get_module("json") @@ -57,22 +57,10 @@ def to_html( is included in the output. HTML files generated with this option are fully self-contained and can be used offline. - If 'cdn', a script tag that references the plotly.js CDN is included - in the output. The url used is versioned to match the bundled plotly.js. - HTML files generated with this option are about 3MB smaller than those - generated with include_plotlyjs=True, but they require an active - internet connection in order to load the plotly.js library. - If 'directory', a script tag is included that references an external 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,28 +242,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": - load_plotlyjs = """\ - {win_config} - \ - """.format( - win_config=_window_plotly_config, cdn_url=plotly_cdn_url() - ) - - elif include_plotlyjs == "directory": + if include_plotlyjs == "directory": load_plotlyjs = """\ {win_config} \ @@ -343,10 +313,8 @@ def to_html(
\ \ """.format( mathjax_script=mathjax_script, @@ -355,9 +323,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: @@ -414,12 +380,6 @@ def write_html( is included in the output. HTML files generated with this option are fully self-contained and can be used offline. - If 'cdn', a script tag that references the plotly.js CDN is included - in the output. The url used is versioned to match the bundled plotly.js. - HTML files generated with this option are about 3MB smaller than those - generated with include_plotlyjs=True, but they require an active - internet connection in order to load the plotly.js library. - If 'directory', a script tag is included that references an external plotly.min.js bundle that is assumed to reside in the same directory as the HTML file. If `file` is a string to a local file @@ -433,12 +393,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/io/_utils.py b/packages/python/plotly/plotly/io/_utils.py index 658540ca71a..e3ca5490587 100644 --- a/packages/python/plotly/plotly/io/_utils.py +++ b/packages/python/plotly/plotly/io/_utils.py @@ -41,10 +41,3 @@ def validate_coerce_output_type(output_type): Must be one of: 'Figure', 'FigureWidget'""" ) return cls - - -def plotly_cdn_url(cdn_ver=get_plotlyjs_version()): - """Return a valid plotly CDN url.""" - return "https://cdn.plot.ly/plotly-{cdn_ver}.min.js".format( - cdn_ver=cdn_ver, - ) diff --git a/packages/python/plotly/plotly/tests/test_core/test_offline/test_offline.py b/packages/python/plotly/plotly/tests/test_core/test_offline/test_offline.py index 37076f501ad..a45fd1a1216 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_offline/test_offline.py +++ b/packages/python/plotly/plotly/tests/test_core/test_offline/test_offline.py @@ -9,7 +9,6 @@ import plotly import plotly.io as pio -from plotly.io._utils import plotly_cdn_url packages_root = os.path.dirname( os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(plotly.__file__)))) @@ -36,9 +35,6 @@ """ -cdn_script = ''.format( - cdn_url=plotly_cdn_url() -) directory_script = '' @@ -124,7 +120,6 @@ def test_including_plotlyjs_truthy_html(self): self.assertIn(plotly_config_script, html) self.assertIn(PLOTLYJS, html) - self.assertNotIn(cdn_script, html) self.assertNotIn(directory_script, html) def test_including_plotlyjs_truthy_div(self): @@ -137,7 +132,6 @@ def test_including_plotlyjs_truthy_div(self): self.assertIn(plotly_config_script, html) self.assertIn(PLOTLYJS, html) - self.assertNotIn(cdn_script, html) self.assertNotIn(directory_script, html) def test_including_plotlyjs_false_html(self): @@ -156,7 +150,6 @@ def test_including_plotlyjs_false_html(self): self.assertNotIn(plotly_config_script, html) self.assertNotIn(PLOTLYJS, html) - self.assertNotIn(cdn_script, html) self.assertNotIn(directory_script, html) def test_including_plotlyjs_false_div(self): @@ -166,33 +159,6 @@ def test_including_plotlyjs_false_div(self): ) self.assertNotIn(plotly_config_script, html) self.assertNotIn(PLOTLYJS, html) - self.assertNotIn(cdn_script, html) - self.assertNotIn(directory_script, html) - - def test_including_plotlyjs_cdn_html(self): - for include_plotlyjs in ["cdn", "CDN", "Cdn"]: - html = self._read_html( - plotly.offline.plot( - fig, - include_plotlyjs=include_plotlyjs, - output_type="file", - filename=html_filename, - auto_open=False, - ) - ) - self.assertIn(plotly_config_script, html) - self.assertNotIn(PLOTLYJS, html) - self.assertIn(cdn_script, html) - self.assertNotIn(directory_script, html) - - def test_including_plotlyjs_cdn_div(self): - for include_plotlyjs in ["cdn", "CDN", "Cdn"]: - html = plotly.offline.plot( - fig, include_plotlyjs=include_plotlyjs, output_type="div" - ) - self.assertIn(plotly_config_script, html) - self.assertNotIn(PLOTLYJS, html) - self.assertIn(cdn_script, html) self.assertNotIn(directory_script, html) def test_including_plotlyjs_directory_html(self): @@ -209,7 +175,6 @@ def test_including_plotlyjs_directory_html(self): ) self.assertIn(plotly_config_script, html) self.assertNotIn(PLOTLYJS, html) - self.assertNotIn(cdn_script, html) self.assertIn(directory_script, html) # plot creates plotly.min.js in the output directory @@ -230,7 +195,6 @@ def test_including_plotlyjs_directory_div(self): self.assertIn(plotly_config_script, html) self.assertNotIn(PLOTLYJS, html) - self.assertNotIn(cdn_script, html) self.assertIn(directory_script, html) # plot does NOT create a plotly.min.js file in the output directory @@ -257,7 +221,6 @@ def test_including_plotlyjs_path_html(self): ) ) self.assertNotIn(PLOTLYJS, html) - self.assertNotIn(cdn_script, html) self.assertNotIn(directory_script, html) self.assertIn(include_plotlyjs, html) @@ -275,7 +238,6 @@ def test_including_plotlyjs_path_div(self): fig, include_plotlyjs=include_plotlyjs, output_type="div" ) self.assertNotIn(PLOTLYJS, html) - self.assertNotIn(cdn_script, html) self.assertNotIn(directory_script, html) self.assertIn(include_plotlyjs, html) diff --git a/packages/python/plotly/plotly/tests/test_io/test_html.py b/packages/python/plotly/plotly/tests/test_io/test_html.py index a056fd8f872..662e0a9d16b 100644 --- a/packages/python/plotly/plotly/tests/test_io/test_html.py +++ b/packages/python/plotly/plotly/tests/test_io/test_html.py @@ -6,7 +6,6 @@ import plotly.graph_objs as go import plotly.io as pio -from plotly.io._utils import plotly_cdn_url if sys.version_info >= (3, 3): @@ -36,10 +35,6 @@ def fig1(request): # ---- -def test_versioned_cdn_included(fig1): - assert plotly_cdn_url() in pio.to_html(fig1, include_plotlyjs="cdn") - - def test_html_deterministic(fig1): div_id = "plotly-root" assert pio.to_html(fig1, include_plotlyjs="cdn", div_id=div_id) == pio.to_html( 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..95c47f5c260 100644 --- a/packages/python/plotly/plotly/tests/test_io/test_renderers.py +++ b/packages/python/plotly/plotly/tests/test_io/test_renderers.py @@ -12,7 +12,6 @@ import plotly.graph_objs as go import plotly.io as pio from plotly.offline import get_plotlyjs -from plotly.io._utils import plotly_cdn_url if sys.version_info >= (3, 3): import unittest.mock as mock @@ -137,22 +136,10 @@ def assert_not_full_html(html): assert not html.startswith(" \n " - ' ' + ' ' '