-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Allow for the option of a CDN in offline mode #475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
47ebb73
655024e
2461711
0255406
8822ff4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ | |
_matplotlib_imported = False | ||
|
||
__PLOTLY_OFFLINE_INITIALIZED = False | ||
__PLOTLY_USE_CDN = False | ||
|
||
|
||
def download_plotlyjs(download_url): | ||
warnings.warn(''' | ||
|
@@ -46,7 +48,7 @@ def get_plotlyjs(): | |
return plotlyjs | ||
|
||
|
||
def init_notebook_mode(): | ||
def init_notebook_mode(connected=False): | ||
""" | ||
Initialize plotly.js in the browser if it hasn't been loaded into the DOM | ||
yet. This is an idempotent method and can and should be called from any | ||
|
@@ -56,20 +58,40 @@ def init_notebook_mode(): | |
raise ImportError('`iplot` can only run inside an IPython Notebook.') | ||
|
||
global __PLOTLY_OFFLINE_INITIALIZED | ||
# Inject plotly.js into the output cell | ||
script_inject = ( | ||
'' | ||
'<script type=\'text/javascript\'>' | ||
'if(!window.Plotly){{' | ||
'define(\'plotly\', function(require, exports, module) {{' | ||
'{script}' | ||
'}});' | ||
'require([\'plotly\'], function(Plotly) {{' | ||
'window.Plotly = Plotly;' | ||
'}});' | ||
'}}' | ||
'</script>' | ||
'').format(script=get_plotlyjs()) | ||
global __PLOTLY_USE_CDN | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this a |
||
|
||
__PLOTLY_USE_CDN = connected | ||
|
||
if connected: | ||
# Inject plotly.js into the output cell | ||
script_inject = ( | ||
'' | ||
'<script>' | ||
'requirejs.config({' | ||
'paths: { ' | ||
'\'plotly\': [\'https://cdn.plot.ly/plotly-latest.min\']},' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't this supposed to be |
||
'});' | ||
'if(!window.Plotly) {{' | ||
'require([\'plotly\'],' | ||
'function(plotly) {window.Plotly=plotly;});' | ||
'}}' | ||
'</script>' | ||
) | ||
else: | ||
# Inject plotly.js into the output cell | ||
script_inject = ( | ||
'' | ||
'<script type=\'text/javascript\'>' | ||
'if(!window.Plotly){{' | ||
'define(\'plotly\', function(require, exports, module) {{' | ||
'{script}' | ||
'}});' | ||
'require([\'plotly\'], function(Plotly) {{' | ||
'window.Plotly = Plotly;' | ||
'}});' | ||
'}}' | ||
'</script>' | ||
'').format(script=get_plotlyjs()) | ||
|
||
display(HTML(script_inject)) | ||
__PLOTLY_OFFLINE_INITIALIZED = True | ||
|
@@ -126,7 +148,7 @@ def _plot_html(figure_or_data, show_link, link_text, | |
|
||
optional_line1 = ('require(["plotly"], function(Plotly) {{ ' | ||
if global_requirejs else '') | ||
optional_line2 = '}});' if global_requirejs else '' | ||
optional_line2 = ('}});' if global_requirejs else '') | ||
|
||
plotly_html_div = ( | ||
'' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a docstring comment explaining what
connected
is?