30
30
_matplotlib_imported = False
31
31
32
32
__PLOTLY_OFFLINE_INITIALIZED = False
33
- __PLOTLY_USE_CDN = False
34
33
35
34
36
35
def download_plotlyjs (download_url ):
@@ -53,14 +52,31 @@ def init_notebook_mode(connected=False):
53
52
Initialize plotly.js in the browser if it hasn't been loaded into the DOM
54
53
yet. This is an idempotent method and can and should be called from any
55
54
offline methods that require plotly.js to be loaded into the notebook dom.
55
+
56
+ Keyword arguments:
57
+
58
+ connected (default=False) -- If True, the plotly.js library will be loaded
59
+ from an online CDN. If False, the plotly.js library will be loaded locally
60
+ from the plotly python package
61
+
62
+ Use `connected=True` if you want your notebooks to have smaller file sizes.
63
+ In the case where `connected=False`, the entirety of the plotly.js library
64
+ will be loaded into the notebook, which will result in a file-size increase
65
+ of a couple megabytes. Additionally, because the library will be downloaded
66
+ from the web, you and your viewers must be connected to the internet to be
67
+ able to view charts within this notebook.
68
+
69
+ Use `connected=False` if you want you and your collaborators to be able to
70
+ create and view these charts regardless of the availability of an internet
71
+ connection. This is the default option since it is the most predictable.
72
+ Note that under this setting the library will be included inline inside
73
+ your notebook, resulting in much larger notebook sizes compared to the case
74
+ where `connected=True`.
56
75
"""
57
76
if not _ipython_imported :
58
77
raise ImportError ('`iplot` can only run inside an IPython Notebook.' )
59
78
60
79
global __PLOTLY_OFFLINE_INITIALIZED
61
- global __PLOTLY_USE_CDN
62
-
63
- __PLOTLY_USE_CDN = connected
64
80
65
81
if connected :
66
82
# Inject plotly.js into the output cell
@@ -69,14 +85,15 @@ def init_notebook_mode(connected=False):
69
85
'<script>'
70
86
'requirejs.config({'
71
87
'paths: { '
88
+ # Note we omit the extension .js because require will include it.
72
89
'\' plotly\' : [\' https://cdn.plot.ly/plotly-latest.min\' ]},'
73
90
'});'
74
91
'if(!window.Plotly) {{'
75
92
'require([\' plotly\' ],'
76
93
'function(plotly) {window.Plotly=plotly;});'
77
94
'}}'
78
95
'</script>'
79
- )
96
+ )
80
97
else :
81
98
# Inject plotly.js into the output cell
82
99
script_inject = (
0 commit comments