From 729ae8cdcb9d32c2b25c3960c91d4c4fafc09854 Mon Sep 17 00:00:00 2001 From: Martha Cryan Date: Tue, 25 Mar 2025 12:55:10 -0500 Subject: [PATCH 1/2] Fix issue of plotly.js being embedded twice in notebook --- plotly/io/_base_renderers.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/plotly/io/_base_renderers.py b/plotly/io/_base_renderers.py index 535b2e789e2..592adcf0fe1 100644 --- a/plotly/io/_base_renderers.py +++ b/plotly/io/_base_renderers.py @@ -254,6 +254,7 @@ def __init__( auto_play=False, post_script=None, animation_opts=None, + include_plotlyjs=True, ): self.config = dict(config) if config else {} @@ -263,6 +264,7 @@ def __init__( self.full_html = full_html self.animation_opts = animation_opts self.post_script = post_script + self.include_plotlyjs = 'cdn' if self.connected else include_plotlyjs def activate(self): if self.global_init: @@ -307,12 +309,7 @@ def to_mimebundle(self, fig_dict): from plotly.io import to_html - if self.connected: - include_plotlyjs = "cdn" - include_mathjax = "cdn" - else: - include_plotlyjs = True - include_mathjax = "cdn" + include_mathjax = "cdn" # build post script post_script = [ @@ -352,7 +349,7 @@ def to_mimebundle(self, fig_dict): fig_dict, config=self.config, auto_play=self.auto_play, - include_plotlyjs=include_plotlyjs, + include_plotlyjs=self.include_plotlyjs, include_mathjax=include_mathjax, post_script=post_script, full_html=self.full_html, @@ -385,6 +382,7 @@ def __init__( auto_play=False, post_script=None, animation_opts=None, + include_plotlyjs=False, ): super(NotebookRenderer, self).__init__( connected=connected, @@ -394,6 +392,7 @@ def __init__( auto_play=auto_play, post_script=post_script, animation_opts=animation_opts, + include_plotlyjs=include_plotlyjs, ) @@ -421,6 +420,7 @@ def __init__( auto_play=auto_play, post_script=post_script, animation_opts=animation_opts, + include_plotlyjs=False, ) @@ -448,6 +448,7 @@ def __init__( auto_play=auto_play, post_script=post_script, animation_opts=animation_opts, + include_plotlyjs=False, ) From f39dbfd11109d559417640102a86855036e45d38 Mon Sep 17 00:00:00 2001 From: Martha Cryan Date: Tue, 25 Mar 2025 16:12:23 -0500 Subject: [PATCH 2/2] Black --- plotly/io/_base_renderers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plotly/io/_base_renderers.py b/plotly/io/_base_renderers.py index 592adcf0fe1..d683d1694f1 100644 --- a/plotly/io/_base_renderers.py +++ b/plotly/io/_base_renderers.py @@ -264,7 +264,7 @@ def __init__( self.full_html = full_html self.animation_opts = animation_opts self.post_script = post_script - self.include_plotlyjs = 'cdn' if self.connected else include_plotlyjs + self.include_plotlyjs = "cdn" if self.connected else include_plotlyjs def activate(self): if self.global_init: