From 47ebb73d7fdca325dd1090e63613574b34e36133 Mon Sep 17 00:00:00 2001 From: yankev Date: Sat, 21 May 2016 23:22:12 -0400 Subject: [PATCH 1/5] bad fix --- plotly/offline/offline.py | 46 +++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 170bf8f3cfa..d07c44e8e4d 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -30,6 +30,8 @@ _matplotlib_imported = False __PLOTLY_OFFLINE_INITIALIZED = False +__PLOTLY_USE_CDN = False + def download_plotlyjs(download_url): warnings.warn(''' @@ -46,7 +48,7 @@ def get_plotlyjs(): return plotlyjs -def init_notebook_mode(): +def init_notebook_mode(connected=False): """ Initialize plotly.js in the browser if it hasn't been loaded into the DOM yet. This is an idempotent method and can and should be called from any @@ -56,20 +58,32 @@ def init_notebook_mode(): raise ImportError('`iplot` can only run inside an IPython Notebook.') global __PLOTLY_OFFLINE_INITIALIZED - # Inject plotly.js into the output cell - script_inject = ( - '' - '' - '').format(script=get_plotlyjs()) + global __PLOTLY_USE_CDN + + __PLOTLY_USE_CDN = connected + + if connected: + # Inject plotly.js into the output cell + script_inject = ( + '' + '' + ) + else: + # Inject plotly.js into the output cell + script_inject = ( + '' + '' + '').format(script=get_plotlyjs()) display(HTML(script_inject)) __PLOTLY_OFFLINE_INITIALIZED = True @@ -193,7 +207,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', plot_html, plotdivid, width, height = _plot_html( figure_or_data, show_link, link_text, validate, - '100%', 525, global_requirejs=True) + '100%', 525, global_requirejs=__PLOTLY_USE_CDN) display(HTML(plot_html)) From 655024e4fb98ef75d3671d2125f1d8bcf86535f2 Mon Sep 17 00:00:00 2001 From: yankev Date: Sun, 22 May 2016 00:38:40 -0400 Subject: [PATCH 2/5] add more conditions for the use of optional require lines --- plotly/offline/offline.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index d07c44e8e4d..7bcd12e5ac1 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -139,8 +139,9 @@ def _plot_html(figure_or_data, show_link, link_text, config=jconfig) optional_line1 = ('require(["plotly"], function(Plotly) {{ ' - if global_requirejs else '') - optional_line2 = '}});' if global_requirejs else '' + if (global_requirejs and (not __PLOTLY_USE_CDN)) else '') + optional_line2 = ('}});' if (global_requirejs and (not __PLOTLY_USE_CDN)) + else '') plotly_html_div = ( '' From 2461711109902b2e631b64eef4ad8d9b55df3fd6 Mon Sep 17 00:00:00 2001 From: yankev Date: Wed, 25 May 2016 12:03:25 -0400 Subject: [PATCH 3/5] added require statement, but plots don't persist in cdn mode --- plotly/offline/offline.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 7bcd12e5ac1..05a669f4ba6 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -66,9 +66,12 @@ def init_notebook_mode(connected=False): # Inject plotly.js into the output cell script_inject = ( '' - '' - ) + '' + ) else: # Inject plotly.js into the output cell script_inject = ( @@ -208,7 +211,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', plot_html, plotdivid, width, height = _plot_html( figure_or_data, show_link, link_text, validate, - '100%', 525, global_requirejs=__PLOTLY_USE_CDN) + '100%', 525, global_requirejs=True) display(HTML(plot_html)) From 02554062279f6aa020050392165b8203083d3ef5 Mon Sep 17 00:00:00 2001 From: yankev Date: Wed, 25 May 2016 13:09:33 -0400 Subject: [PATCH 4/5] removed window.Plotly check and removed extra conditions on optional require lines --- plotly/offline/offline.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 05a669f4ba6..2034e9383a3 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -67,10 +67,15 @@ def init_notebook_mode(connected=False): script_inject = ( '' '' + # '}}' + '' ) else: # Inject plotly.js into the output cell @@ -142,9 +147,8 @@ def _plot_html(figure_or_data, show_link, link_text, config=jconfig) optional_line1 = ('require(["plotly"], function(Plotly) {{ ' - if (global_requirejs and (not __PLOTLY_USE_CDN)) else '') - optional_line2 = ('}});' if (global_requirejs and (not __PLOTLY_USE_CDN)) - else '') + if global_requirejs else '') + optional_line2 = ('}});' if global_requirejs else '') plotly_html_div = ( '' From 8822ff479817d4bfd32517718541f87269163394 Mon Sep 17 00:00:00 2001 From: yankev Date: Wed, 25 May 2016 13:48:26 -0400 Subject: [PATCH 5/5] reintroduced window.Plotly check --- plotly/offline/offline.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 2034e9383a3..d782fa65a7a 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -67,14 +67,14 @@ def init_notebook_mode(connected=False): script_inject = ( '' '' ) else: