Skip to content

Commit 742f944

Browse files
committed
make init_notebook_mode idempotent
Fixes plotly#458 Running `init_notebook_mode` injects plotly.js into the output cell. Before, if you ran it twice, it would clear the output cell on the second call and remove plotly.js from DOM. This was deceiving, because any existing plots on the page wouldn’t disappear even though their underlying plotly.js was no longer present. But, if you refresh the page, the plots would not render (as plotly.js was no longer in the output cell)
1 parent 0a57c11 commit 742f944

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

plotly/offline/offline.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ def init_notebook_mode():
6060
from IPython.display import HTML, display
6161

6262
global __PLOTLY_OFFLINE_INITIALIZED
63-
if not __PLOTLY_OFFLINE_INITIALIZED:
64-
display(HTML("<script type='text/javascript'>" +
65-
"define('plotly', function(require, exports, module) {" +
66-
get_plotlyjs() +
67-
"});" +
68-
"require(['plotly'], function(Plotly) {" +
69-
"window.Plotly = Plotly;" +
70-
"});" +
71-
"</script>"))
63+
# ALways display the script so that init_notebook_mode is idempotent
64+
display(HTML("<script type='text/javascript'>" +
65+
"define('plotly', function(require, exports, module) {" +
66+
get_plotlyjs() +
67+
"});" +
68+
"require(['plotly'], function(Plotly) {" +
69+
"window.Plotly = Plotly;" +
70+
"});" +
71+
"</script>"))
7272
__PLOTLY_OFFLINE_INITIALIZED = True
7373

7474

0 commit comments

Comments
 (0)