Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 577177c

Browse filesBrowse 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
Copy full SHA for 577177c

File tree

Expand file treeCollapse file tree

1 file changed

+9
-8
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-8
lines changed

‎plotly/offline/offline.py

Copy file name to clipboardExpand all lines: plotly/offline/offline.py
+9-8Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.