Downloadbttn and downloadhandler

Trying to let available a ggplot chart to the user, see what I did in ui:

shinyWidgets::downloadBttn("dwnldbtnTB1_1", "Download")

and in server:

bxpltDT1 <- reactive({
          as.data.frame(
          agrocorrigidoMGBA %>% dplyr::select(ESTADO, ANO, MUNICIPIO, Producao = input$cultivoTB1) %>% 
              dplyr::filter(ESTADO == input$estadoTB1)
          )
      })
      
      output$p1t1 <- renderPlot({
          
         ggplot(data = bxpltDT1(), mapping = aes(x = ANO, y = Producao)) +
              geom_smooth(method = input$metodoTB1, se = FALSE) +
              labs(
                title = stringr::str_c("Representação da produção: ", input$cultivoTB1),
                x = "Ano",
                y = "Valor de Produção (x1000 reais)"
              ) +
          theme_minimal()
      
    }
    )
      
      output$dwnldbtnTB1_1 <- downloadHandler(
        filename = function() {
          paste("Smooth_Agro_MG", Sys.Date(), ".png", sep = "")
        },
        content = function(file){
          png(file)
          ggplot(data = bxpltDT1(), mapping = aes(x = ANO, y = Producao)) +
            geom_smooth(method = input$metodoTB1, se = FALSE) +
            labs(
              title = stringr::str_c("Representação da produção: ", input$cultivoTB1),
              x = "Ano",
              y = "Valor de Produção (x1000 reais)"
            ) +
            theme_minimal()
          dev.off()
        }
      )

The result is a empty png document when I chick in the download button. Any suggestion?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.