Download computationally intensive renderPlot result as an eps without re-plotting?

Shiny App Here:

To reduce time, I've set up a remote cache on AWS for the displayed plots, as it takes ~1 min to generate each without a cache. However, I wanted to add an option for users to download the displayed plot, and was hoping to find a way to do this without having to re-plot each time.

Here is the current downloadHandler code, but despite the fact that pt1() is cached when renderPlot is run, clicking to download leads to shiny re-plotting.

output$downloadPlot <- downloadHandler(
filename = function() {
paste0("Enhancer_Visual_Index_", sep = "", input$index, ".eps")
content = function(file) {
"Generating visual for download in EPS format. This may take a minute or two...",
footer = NULL
cairo_ps(file, height = 25)

Any advice would be appreciated! Thank you

I had a similar problem in the past. I worked around it by adding this line at the top of my server function vals <- reactiveValues(plot1=NULL, plot2=NULL)

I then had all the computational code. Before generating the final plot I saved it like this: vals$plot1<-plot( What every you are plotting goes here)

to download a PDF I called the vals$plot1

            output$export = downloadHandler(
                filename = function() {"plots.eps"},
                content = function(file) {
                    pdf(file, onefile = TRUE)

You may be able to call vals$plot using the your download handler, as the one I used generates PDFs.