I would like to save/download my barplots in shiny. I did it with ggplot, with ggsave and it was possible, but how can I do it for barplot()? My code in ui.R is:
library(shiny)
library(shinydashboard)
library(ggplot2)
ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    box(
      title = "", 
      status = "danger", 
      solidHeader = TRUE,
      plotOutput(outputId = "myPlotMdata1")
    ),
    box(
      title = "", 
      status = "danger", 
      solidHeader = TRUE,
      plotOutput(outputId = "myPlotMdata2")
    ),
    box(
      title = "", 
      status = "danger", 
      solidHeader = TRUE,
      plotOutput(outputId = "myPlotMdata3")
    ),
    box(
      title = "", 
      status = "danger", 
      solidHeader = TRUE,
      plotOutput(outputId = "myPlotMdata4")
    ),
    box(
      title = "Download", 
      status = "success", 
      solidHeader = TRUE,
      width = 12,
      radioButtons("formatTopwords", "Document format", c("PNG"="png", "EPS"="eps", "PDF"="pdf"), inline = TRUE),
      downloadButton("downloadReportTopwords")
    )
  )
) 
server <- function(input, output) {
  output$myPlotMdata1 <- renderPlot({
    barplot(TopWords$lassoInfPos, las = 2, names.arg = TopWords$informedPos, main = "Informed Investor Top 15 positive words", ylab = "Lasso coefficient")
  })
  output$myPlotMdata2 <- renderPlot({
    barplot(TopWords$lassoNoisePos , las = 2, names.arg = TopWords$noisePos, main = "Noise Investor Top 15 positive words", ylab = "Lasso coefficient")
  })
  output$myPlotMdata3 <- renderPlot({
    barplot(TopWords$lassoInfNeg, las = 2, names.arg = TopWords$informedNeg, main = "Informed Investor Top 15 negative words", ylab = "Lasso coefficient")
  })
  output$myPlotMdata4 <- renderPlot({
    barplot(TopWords$lassoNoiseNeg, las = 2, names.arg = TopWords$noiseNeg, main = "Noise Investor Top 15 negative words", ylab = "Lasso coefficient")
  })
  fn <- reactive({paste("Plot",input$formatTopwords,sep = ".")})
  d <- reactive({input$formatTopwords})
  output$downloadReportTopwords <- downloadHandler(
    filename = fn,
    content = function(file) {
      #ggsave I use for another function, how can I save barplots here
      ggsave(file, device=d(), dpi = 600, width = 297, height = 210, units = "mm")
    }
  )
}  
shinyApp(ui, server)
 
     
    