Skip to content

Commit 962c881

Browse files
committed
prevent users from calling iplot before they initialize plotly.js.
otherwise, they'll see a real gnarly ipython js error.
1 parent c653188 commit 962c881

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

plotly/offline.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
PLOTLY_OFFLINE_BUNDLE = os.path.join(PLOTLY_OFFLINE_DIRECTORY,
2020
'plotly-ipython-offline-bundle.js')
2121

22+
__PLOTLY_OFFLINE_INITIALIZED = False
23+
2224

2325
def download_plotlyjs(download_url):
2426
if not os.path.exists(plotlyjs_path):
@@ -55,13 +57,24 @@ def init_notebook_mode():
5557
'Questions? [email protected].'
5658
.format(source_path=PLOTLY_OFFLINE_BUNDLE))
5759

60+
global __PLOTLY_OFFLINE_INITIALIZED
61+
__PLOTLY_OFFLINE_INITIALIZED = True
5862
display(HTML('<script type="text/javascript">' +
5963
open(PLOTLY_OFFLINE_BUNDLE).read() + '</script>'))
6064

6165

6266
def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly'):
6367
"""
6468
"""
69+
if not __PLOTLY_OFFLINE_INITIALIZED:
70+
raise exceptions.PlotlyError('\n'.join([
71+
'Plotly Offline mode has not been initialized in this notebook. '
72+
'Run: ',
73+
'',
74+
'import plotly',
75+
'plotly.offline.init_notebook_mode() '
76+
'# run at the start of every ipython notebook',
77+
]))
6578
from IPython.display import HTML, display
6679
if isinstance(figure_or_data, dict):
6780
data = figure_or_data['data']

0 commit comments

Comments
 (0)