Save plotly graphs in Shiny

Is it possible to save a plotly graph in Shiny using the downloadHandler?

I know that Shiny supports this for ggplots, see e.g. http://stackoverflow.com/questions/14810409/save-plots-made-in-a-shiny-app

And I’m aware of the plotly_IMAGE() functions, but I get an error:

Error in process.image(struct(resp, "image")) : Unauthorized (HTTP 401).

When I do the following:

  output$downloadPlots <- downloadHandler(
    filename = function() { paste("test", '.png', sep='') },
    content = function(file) {
      plotly_IMAGE(patientCircleInput(), format = "png", out_file = file)
    }
  )

Here patientCircleInput() creates a pie chart that is working.

EDIT:

I now see that it might not be possible using plotly_IMAGE based on this question: http://stackoverflow.com/questions/33998996/exporting-png-files-from-plotly-in-r-without-internet?lq=1

Any inputs are welcome.

I got it to work. I just had to set the environment variables as described here:

I got download handler to work on saving a plotly object with setting api key and username. But the responding time of saving the plot after clicking on the download button is relatively long compared to when using download handler on saving a ggplot or base R plot. Any suggestions on how to deal with the long responding time? Thanks!