@@ -238,31 +238,27 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
238
238
239
239
display (HTML (plot_html ))
240
240
241
- # Use the plot id to download the image now:
242
-
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);'
248
- 'var div_id = document.getElementById(\' {plot_id}\' );'
249
- 'setTimeout(function() {{Plotly.downloadImage(div_id, {{format: \' {format}\' , '
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);'
241
+ # Write script to download image of the plot
242
+ script = ('<script>'
243
+ 'function downloadimage(format, height, width,'
244
+ ' filename) {{'
245
+ 'var p = document.getElementById(\' {plot_id}\' );'
246
+ 'Plotly.downloadImage(p, {{format: format, height: height, '
247
+ 'width: width, filename: filename}});'
248
+ '}};'
249
+ 'if(document.readyState == \' complete\' ) {{'
250
+ 'downloadimage(\' {format}\' , {height}, {width}, \' {filename}\' );'
259
251
'}}'
260
252
'</script>'
261
253
).format (format = format , width = _width , height = _height ,
262
254
filename = filename , plot_id = plot_id )
263
-
255
+ # allow time for the plot to draw
256
+ import time
257
+ time .sleep (1 )
258
+ #inject code to download an image of the plot
264
259
display (HTML (script ))
265
260
261
+
266
262
def plot (figure_or_data ,
267
263
show_link = True , link_text = 'Export to plot.ly' ,
268
264
validate = True , output_type = 'file' ,
0 commit comments