Skip to content

Updating cdn-options PR #492

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

Merged
merged 3 commits into from
May 31, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions plotly/offline/offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
_matplotlib_imported = False

__PLOTLY_OFFLINE_INITIALIZED = False
__PLOTLY_USE_CDN = False


def download_plotlyjs(download_url):
Expand All @@ -53,14 +52,17 @@ 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
offline methods that require plotly.js to be loaded into the notebook dom.

Keyword arguments:

connected (default=False) -- if connected is True, this means that the
plotly.js library will be loaded from a CDN(online) rather than the
local file from pip.
Copy link
Member

@chriddyp chriddyp May 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this explains what it is doing, it doesn't really explain why. What if instead:


Arguments:

connected (default=False) -- If True, plotly.js library will be loaded from an online CDN. If False, plotly.js is loaded locally from this python package.

Use connected = True if you want your notebooks to have a smaller file size. plotly.js is a multi-megabyte file and when connected = False, the entire library is included inline inside the notebook. When connected = True, the library is downloaded from the web when you view the notebook. Since the library will be downloaded from the web, you and your viewers must be connected to the internet to be able to view this notebook's charts.

Use connected = False if you want you and your collaborators to be able to view and create charts regardless of your internet connection. This is the default option since it is the most predictable. Since the library will be included inline inside your notebook, this makes your notebooks considerably larger than if you were using connected = True.

"""
if not _ipython_imported:
raise ImportError('`iplot` can only run inside an IPython Notebook.')

global __PLOTLY_OFFLINE_INITIALIZED
global __PLOTLY_USE_CDN

__PLOTLY_USE_CDN = connected

if connected:
# Inject plotly.js into the output cell
Expand All @@ -76,7 +78,7 @@ def init_notebook_mode(connected=False):
'function(plotly) {window.Plotly=plotly;});'
'}}'
'</script>'
)
)
else:
# Inject plotly.js into the output cell
script_inject = (
Expand Down