def get_image_download_script(caller):
 if (caller == 'iplot'):
  check_start = "if(document.readyState == 'complete') {{"
  check_end = '}}'
 elif (caller == 'plot'):
  check_start = ''
  check_end = ''
 else:
  raise ValueError('caller should only be one of `iplot` or `plot`')
 return (((("<script>function downloadimage(format, height, width, filename) {{var p = document.getElementById('{plot_id}');Plotly.downloadImage(p, {{format: format, height: height, width: width, filename: filename}});}};" + check_start) + "{{downloadimage('{format}', {height}, {width}, '{filename}');}}") + check_end) + '</script>')

def get_image_download_script ( caller ) : if ( caller == 'iplot' ) : check_start = "if(document.readyState == 'complete') {{" check_end = '}}' elif ( caller == 'plot' ) : check_start = '' check_end = '' else : raise ValueError ( 'caller should only be one of `iplot` or `plot`' ) return ( ( ( ( "<script>function downloadimage(format, height, width, filename) {{var p = document.getElementById('{plot_id}');Plotly.downloadImage(p, {{format: format, height: height, width: width, filename: filename}});}};" + check_start ) + "{{downloadimage('{format}', {height}, {width}, '{filename}');}}" ) + check_end ) + '</script>' )
this function will return a script that will download an image of a plotly plot .