Skip to content

Commit f573f50

Browse files
jonmmeasemichaelbabyn
authored andcommitted
Prevent iplot from breaking when Jupyter notebook has headline named "Plotly" (plotly#1250)
This PR works around the issue where a Jupyter Notebook heading named "Plotly" clashes with the window.Plotly variable where we store the plotly.js module. The workaround is to name this variable the much less likely _Plotly
1 parent bef8547 commit f573f50

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

plotly/offline/offline.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ def init_notebook_mode(connected=False):
204204
# Note we omit the extension .js because require will include it.
205205
'\'plotly\': [\'https://cdn.plot.ly/plotly-latest.min\']}},'
206206
'}});'
207-
'if(!window.Plotly) {{'
207+
'if(!window._Plotly) {{'
208208
'require([\'plotly\'],'
209-
'function(plotly) {{window.Plotly=plotly;}});'
209+
'function(plotly) {{window._Plotly=plotly;}});'
210210
'}}'
211211
'</script>'
212212
).format(win_config=_window_plotly_config,
@@ -217,12 +217,12 @@ def init_notebook_mode(connected=False):
217217
'{win_config}'
218218
'{mathjax_config}'
219219
'<script type=\'text/javascript\'>'
220-
'if(!window.Plotly){{'
220+
'if(!window._Plotly){{'
221221
'define(\'plotly\', function(require, exports, module) {{'
222222
'{script}'
223223
'}});'
224224
'require([\'plotly\'], function(Plotly) {{'
225-
'window.Plotly = Plotly;'
225+
'window._Plotly = Plotly;'
226226
'}});'
227227
'}}'
228228
'</script>'

plotly/tests/test_optional/test_jupyter/js_tests/connected_false.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test('should inject raw plotly.js code into DOM', function(t) {
2424
nodes = Array.prototype.slice.call(nodes, 0, 10);
2525

2626
var results = nodes.filter(function(node) {
27-
return node.innerHTML.substr(0, 19) === 'if(!window.Plotly){';
27+
return node.innerHTML.substr(0, 20) === 'if(!window._Plotly){';
2828
});
2929

3030
t.equal(results.length, 1);

0 commit comments

Comments
 (0)