Skip to content

Allow init_notebook_mode to redefine/reinitialize plotly.js each time it's run #1452

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 2 commits into from
Mar 6, 2019
Merged
Changes from all commits
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
15 changes: 11 additions & 4 deletions plotly/offline/offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def _build_resize_script(plotdivid, plotly_root='Plotly'):
resize_script = (
'<script type="text/javascript">'
'window.addEventListener("resize", function(){{'
'{plotly_root}.Plots.resize(document.getElementById("{id}"));}});'
'if (document.getElementById("{id}")) {{'
'{plotly_root}.Plots.resize(document.getElementById("{id}"));'
'}};}})'
'</script>'
).format(plotly_root=plotly_root, id=plotdivid)
return resize_script
Expand Down Expand Up @@ -289,14 +291,13 @@ def init_notebook_mode(connected=False):
'{win_config}'
'{mathjax_config}'
'<script type=\'text/javascript\'>'
'if(!window._Plotly){{'
'require.undef("plotly");'
'define(\'plotly\', function(require, exports, module) {{'
'{script}'
'}});'
'require([\'plotly\'], function(Plotly) {{'
'window._Plotly = Plotly;'
'}});'
'}}'
'</script>'
'').format(script=get_plotlyjs(),
win_config=_window_plotly_config,
Expand Down Expand Up @@ -356,12 +357,14 @@ def _plot_html(figure_or_data, config, validate, default_width,
animate = ''

script = '''
if (document.getElementById("{id}")) {{
Plotly.plot(
'{id}',
{data},
{layout},
{config}
).then(function () {add_frames}){animate}
}}
'''.format(
id=plotdivid,
data=jdata,
Expand All @@ -373,7 +376,11 @@ def _plot_html(figure_or_data, config, validate, default_width,
animate=animate
)
else:
script = 'Plotly.newPlot("{id}", {data}, {layout}, {config})'.format(
script = """
if (document.getElementById("{id}")) {{
Plotly.newPlot("{id}", {data}, {layout}, {config});
}}
""".format(
id=plotdivid,
data=jdata,
layout=jlayout,
Expand Down