Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 577177c

Browse files
committed
Change to offline.init_notebook_mode()
Make init_notebook_mode() only import the JS library once. Otherwise if someone puts it at the top of a Jupyter cell and it gets executed every time (typical pattern of usage?), it adds ~1 s to the cell's execution time.
1 parent 77f86cc commit 577177c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

plotly/offline/offline.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ def init_notebook_mode():
4646
from IPython.display import HTML, display
4747

4848
global __PLOTLY_OFFLINE_INITIALIZED
49+
if not __PLOTLY_OFFLINE_INITIALIZED:
50+
display(HTML('<script type="text/javascript">' +
51+
# ipython's includes `require` as a global, which
52+
# conflicts with plotly.js. so, unrequire it.
53+
'require=requirejs=define=undefined;' +
54+
'</script>' +
55+
'<script type="text/javascript">' +
56+
get_plotlyjs() +
57+
'</script>'))
4958
__PLOTLY_OFFLINE_INITIALIZED = True
50-
display(HTML('<script type="text/javascript">' +
51-
# ipython's includes `require` as a global, which
52-
# conflicts with plotly.js. so, unrequire it.
53-
'require=requirejs=define=undefined;' +
54-
'</script>' +
55-
'<script type="text/javascript">' +
56-
get_plotlyjs() +
57-
'</script>'))
5859

5960

6061
def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',

0 commit comments

Comments
 (0)