Skip to content

Commit 8eae6bd

Browse files
committed
attempt at stopping image download on future notebook openings
1 parent 17485bc commit 8eae6bd

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

plotly/offline/offline.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,23 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
240240

241241
# Use the plot id to download the image now:
242242

243-
script = ('<script>'
243+
script = ('<script id=\'download-script-{plot_id}\'>'
244+
'var completed = document.getElementById(\'downloaded-plot-{plot_id}\');'
245+
'alert(completed);'
246+
'if(!completed) {{'
247+
'console.log(completed);'
244248
'var div_id = document.getElementById(\'{plot_id}\');'
245249
'setTimeout(function() {{Plotly.downloadImage(div_id, {{format: \'{format}\', '
246-
'height: {height}, width: {width}, filename: \'{filename}\'}});}}, 500);'
250+
'height: {height}, width: {width}, filename: \'{filename}\'}})'
251+
'.then(function(){{'
252+
'var complete = document.createElement(\'span\');'
253+
'complete.id = \'downloaded-plot-{plot_id}\';'
254+
'var thisScript = document.getElementById(\'download-script-{plot_id}\');'
255+
'console.log(complete);'
256+
'thisScript.parentNode.insertBefore(complete, thisScript.nextSibling);'
257+
'}})'
258+
';}}, 500);'
259+
'}}'
247260
'</script>'
248261
).format(format=format, width=_width, height=_height,
249262
filename=filename, plot_id=plot_id)

0 commit comments

Comments
 (0)