diff --git a/server.R b/server.R index 553404c9a65a9bd534c67e02b7dc9ecaaf3a803f..55803d7f030f9266ea37c333f07b55dca342cdf7 100644 --- a/server.R +++ b/server.R @@ -1246,10 +1246,101 @@ shinyServer label = "Barycenters : ", choices = c("..." = 0, sample_variables(data16S())) ), - collapsedBox(verbatimTextOutput("acpScript"), title = "RCode") + collapsedBox(verbatimTextOutput("acpScript"), title = "RCode"), + actionButton("downloadSetting", label = "Download plot") ) }) + observeEvent(input$downloadSetting, { + showModal( + modalDialog( + title = "Setting of downloading plot", + textInput( + "plotName", + label = "Plot name : ", + value = "Easy16S-plot" + ), + numericInput( + "plotWidth", + label = "Plot width (cm) : ", + value = 20, + min = 1, + max = 100 + ), + numericInput( + "plotHeight", + label = "Plot height (cm) : ", + value = 20, + min = 1, + max = 100 + ), + numericInput( + "plotDPI", + label = "Plot resolution : ", + value = 300, + min = 70, + max = 500, + step = 10 + ), + selectInput( + "plotDevice", + label = "Plot device : ", + choices = list("eps", "ps", "tex", "pdf", "jpeg", "tiff", "png", "bmp", "svg"), + selected = "png" + ), + size = "s", + easyClose = TRUE, + footer = downloadButton(outputId = "downloadPlot", label = "Download the plot") + ) + ) + }) + + output$downloadPlot <- { + downloadHandler( + filename = function() { + paste(input$plotName, input$plotDevice, sep = ".") + }, + content = function(file) { + ggsave( + file, + plot = plotInputACP(), + device = input$plotDevice, + units = "cm", + width = input$plotWidth, + height = input$plotHeight, + dpi = input$plotDPI, + limitsize = FALSE + ) + } + ) + } + + plotInputACP <- function() + { + p <- plot_samples( + data16S(), + ordination = ordinate( + data16S(), + method = input$acpMethod, + distance = input$acpDist + ), + axes = as.numeric(input$acpAxes), + title = checkNull(input$acpTitle), + color = checkNull(input$acpCol), + replicate = if (is.null(checkNull(input$acpRep))) { + NULL + } else { + checkNull(input$acpRep) + }, + shape = checkNull(input$acpShape), + label = checkNull(input$acpLabel) + ) + if (!is.null(checkNull(input$acpEllipse))) { + p <- p + stat_ellipse(aes_string(group = input$acpEllipse)) + } + return(p + theme_bw()) + } + output$acpScript <- renderText({ scriptArgs <- c( "physeq = data", @@ -1298,27 +1389,6 @@ shinyServer need(data16S(), "Requires an abundance dataset"), need(length(input$acpAxes) == 2, "Requires two projections axes") ) - p <- plot_samples( - data16S(), - ordination = ordinate( - data16S(), - method = input$acpMethod, - distance = input$acpDist - ), - axes = as.numeric(input$acpAxes), - title = checkNull(input$acpTitle), - color = checkNull(input$acpCol), - replicate = if (is.null(checkNull(input$acpRep))) { - NULL - } else { - checkNull(input$acpRep) - }, - shape = checkNull(input$acpShape), - label = checkNull(input$acpLabel) - ) - if (!is.null(checkNull(input$acpEllipse))) { - p <- p + stat_ellipse(aes_string(group = input$acpEllipse)) - } - return(p + theme_bw()) + plotInputACP() }) })