From cbcf74eb19d4a856a15e0909daada80a517b4999 Mon Sep 17 00:00:00 2001
From: Cedric Midoux <cedric.midoux@inra.fr>
Date: Mon, 10 Sep 2018 18:22:52 +0200
Subject: [PATCH] clustScript

---
 server.R | 72 ++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 46 insertions(+), 26 deletions(-)

diff --git a/server.R b/server.R
index 596af5e..cf4a028 100644
--- a/server.R
+++ b/server.R
@@ -1,4 +1,5 @@
 library(shinydashboard)
+library(glue)
 
 shinyServer
 (function(input, output, session)
@@ -123,6 +124,22 @@ shinyServer
     })
   }
   
+  scriptHead = paste0(
+    "# Loading packages\n",
+    "source(\"https://raw.githubusercontent.com/mahendra-mariadassou/phyloseq-extended/master/R/load-extra-functions.R\")\n",
+    "\n",
+    "# Loading data\n",
+    paste0(
+      "load(\"",
+      paste("Easy16S-data", Sys.Date(), "RData", sep = "."),
+      "\") # if necessary, adapt the file path\n"
+    ),
+    "\n",
+    "# View data\n",
+    "data\n",
+    "\n"
+  )
+  
   output$downloadData <- {
     downloadHandler(
       filename = function() {
@@ -155,7 +172,7 @@ shinyServer
     validate(
       need(
         data16S(),
-        "Firstly, you should select a demo dataset or upload an abundance BIOM file.\nFor example, with Galaxy, a BIOM file can be obtained at the end of FROGS workflow with the 'FROGS BIOM to std BIOM' tool.\n Make sure that the phyloseq object in the RData file is called 'data'."
+        "Firstly, you should select a demo dataset or upload an abundance BIOM file.\nFor example, with Galaxy, a BIOM file can be obtained at the end of FROGS workflow with the 'FROGS BIOM to std BIOM' tool. \nMake sure that the phyloseq object in the RData file is called 'data'."
       )
     )
     data16S()
@@ -224,40 +241,24 @@ shinyServer
   
   output$histScript <- renderText({
     paste0(
-      "# Loading packages\n",
-      "source(\"https://raw.githubusercontent.com/mahendra-mariadassou/phyloseq-extended/master/R/load-extra-functions.R\")\n",
-      "\n",
-      "# Loading data\n",
-      paste0(
-        "load(\"",
-        paste("Easy16S-data", Sys.Date(), "RData", sep = "."),
-        "\") # if necessary, adapt the file path\n"
-      ),
-      "\n",
-      "# View data\n",
-      "data\n",
-      "\n",
+      scriptHead,
       "# Plot barplot\n",
       "p <- plot_bar(physeq = data",
-      ifelse(
-        is.null(checkNull(input$barFill)),
-        "",
-        paste0(",\n              fill = \"", input$barFill, "\"")
-      ),
-      ifelse(is.null(checkNull(input$barX)), "", paste0(",\n              x = ", input$barX)),
+      glue(", fill = \"{input$barFill}\""),
+      ifelse(is.null(checkNull(input$barX)),
+             "",
+             glue(", x = \"{input$barX}\"")),
       ifelse(
         is.null(checkNull(input$barTitle)),
         "",
-        paste0(",\n              title = \"", input$barTitle, "\"")
+        glue(", title = \"{input$barTitle}\"")
       ),
       ")\n",
       ifelse(
         is.null(checkNull(input$barGrid)),
         "",
-        paste0(
-          "p <- p + facet_grid(\". ~ ",
-          input$barGrid,
-          "\", scales = \"free_x\")\n"
+        glue(
+          "p <- p + facet_grid(\". ~ {input$barGrid}\", scales = \"free_x\")"
         )
       ),
       "\n",
@@ -385,7 +386,26 @@ shinyServer
         "clustCol",
         label = "Color : ",
         choices = c("..." = 0, sample_variables(data16S()))
-      )
+      ),
+      collapsedBox(verbatimTextOutput("clustScript"), title = "RCode")
+    )
+  })
+  
+  output$clustScript <- renderText({
+    paste0(
+      scriptHead,
+      "# Plot barplot\n",
+      "p <- plot_clust(physeq = data",
+      glue(", dist = \"{input$clustDist}\""),
+      glue(", method = \"{input$clustMethod}\""),
+      ifelse(
+        is.null(checkNull(input$clustCol)),
+        "",
+        glue(", color = \"{input$clustCol}\"")
+      ),
+      ")\n",
+      "\n",
+      "plot(p)"
     )
   })
   
-- 
GitLab