Shiny export via .zip that contains .csv and .png

Hello,

I have this very basic toy example setup. I would like to have the third download in the zip to be a graph from a renderPlot({}) object but I am not entirely sure how you would go about defining and do it within this structure. I saw that there are multiple ways to do it with ggsave etc. What is the easiest way within this structure to export a png of say mtcars when i == 3?

library(shiny)

runApp(
  list(server = function(input, output) {  
    output$downloadData <- downloadHandler(
      filename = function() {
        paste("output", "zip", sep=".")
      },
      content = function(fname) {
        fs <- c()
        tmpdir <- tempdir()
        setwd(tempdir())
        for (i in c(1,2,3,4,5)) {
          path <- paste0("sample_", i, ".csv")
          fs <- c(fs, path)
          if (i == 1) {write.csv(mtcars,path)} 
          else if (i == 2) {write.csv(state.x77,path)} 
          else {write(i*2, path)}
        }
        zip(zipfile=fname, files=fs)
      },
      contentType = "application/zip"
    )
  }
  , ui = fluidPage(
    titlePanel(""),
    sidebarLayout(
      sidebarPanel(
        downloadButton("downloadData", label = "Download")
      ),
      mainPanel(h6("Sample download", align = "center"))
    )
  ))
)