From 5a66fa87d156ffa4e3e1c16c2465e1a3202c3de1 Mon Sep 17 00:00:00 2001
From: Midoux Cedric <cedric.midoux@irstea.fr>
Date: Mon, 23 Mar 2020 15:55:09 +0100
Subject: [PATCH] plotDownload

---
 panels/dataInput.R | 21 ++++++++++++++++++---
 server.R           |  4 ++++
 ui.R               |  4 ++--
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/panels/dataInput.R b/panels/dataInput.R
index ad424ec..d4f3a6b 100644
--- a/panels/dataInput.R
+++ b/panels/dataInput.R
@@ -175,9 +175,24 @@ output$downloadData <- {
   )
 }
 
-output$downloadPlot <- downloadHandler(
-  filename = function() {"plot.png"},
-  content = function(file) {ggsave(file)}
+plotDownload <- function() {
+  modalDialog(
+    title = "Download last modified plot",
+    size = "s",
+    textInput("plotName", "File name : ", value = "plot"),
+    numericInput("plotWidth", "Width : ", value = 7),
+    numericInput("plotHeight", "Height : ", value = 7),
+    numericInput("plotDPI", "DPI : ", value = 300),
+    radioButtons("plotFormat", "File format : ", choices = c("png", "pdf", "jpeg", "svg", "wmf"), selected = 1, inline = TRUE),
+    footer = tagList(modalButton("Cancel"),
+                     downloadButton("okPlot", "Download")
+                     )
+  )
+}
+
+output$okPlot <- downloadHandler(
+  filename = function() {paste(input$plotName, input$plotFormat, sep = ".")},
+  content = function(file) {ggsave(file, width = input$plotWidth, height = input$plotHeight, dpi = input$plotDPI)}
 )
 
 # output$rarefactionMin <- renderText({
diff --git a/server.R b/server.R
index 9993935..2f8fd37 100644
--- a/server.R
+++ b/server.R
@@ -32,4 +32,8 @@ shinyServer
     showModal(dataInput())
   })
   
+  observeEvent(input$plotButton, {
+    showModal(plotDownload())
+  })
+  
 })
diff --git a/ui.R b/ui.R
index 409df64..d39b4af 100644
--- a/ui.R
+++ b/ui.R
@@ -23,8 +23,8 @@ dashboardHeader(title = "Easy16S"),
                    "Download data as RData", 
                    icon = icon("download"), 
                    style = "width: 80% ; color: black ; background-color: gray90"),
-      downloadButton("downloadPlot",
-                   "Download last plot",
+      actionButton("plotButton", 
+                   "Download last plot", 
                    icon = icon("download"),
                    style = "width: 80% ; color: black ; background-color: gray90"),
     sidebarMenu(
-- 
GitLab