From ece485dbb8752343ca48f6195034f1ba74e9d69b Mon Sep 17 00:00:00 2001
From: Cedric Midoux <cedric.midoux@inra.fr>
Date: Tue, 11 Sep 2018 17:24:16 +0200
Subject: [PATCH] richnessAScript

---
 server.R | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 64 insertions(+), 4 deletions(-)

diff --git a/server.R b/server.R
index 21f8e84..7aa95a2 100644
--- a/server.R
+++ b/server.R
@@ -258,12 +258,13 @@ shinyServer
         is.null(checkNull(input$barGrid)),
         "",
         glue(
-          "p <- p + facet_grid(\". ~ {input$barGrid}\", scales = \"free_x\")"
+          "p <- p + facet_grid(\". ~ {input$barGrid}\", scales = \"free_x\")
+          "
         )
-      ),
+        ),
       "\n",
       "plot(p)"
-    )
+      )
   })
   
   output$histo <- renderPlot({
@@ -530,7 +531,65 @@ shinyServer
         "richnessShape",
         label = "Shape : ",
         choices = c("..." = 0, sample_variables(data16S()))
-      )
+      ),
+      collapsedBox(verbatimTextOutput("richnessAScript"), title = "RCode")
+    )
+  })
+  
+  output$richnessAScript <- renderText({
+    paste0(
+      scriptHead,
+      "# Plot boxplot of alpha diversity\n",
+      "p <- plot_richness(physeq = data",
+      ifelse(
+        is.null(checkNull(input$richnessX)),
+        "",
+        glue(", x = \"{input$richnessX}\"")
+      ),
+      ifelse(
+        is.null(checkNull(input$richnessColor)),
+        "",
+        glue(", color = \"{input$richnessColor}\"")
+      ),
+      ifelse(
+        is.null(checkNull(input$richnessShape)),
+        "",
+        glue(", shape = \"{input$richnessShape}\"")
+      ),
+      ifelse(
+        is.null(checkNull(input$richnessTitle)),
+        "",
+        glue(", title = \"{input$richnessTitle}\"")
+      ),
+      ifelse(
+        is.null(checkNull(input$richnessMeasures)),
+        "",
+        glue(
+          ", measures = c(\"{glue_collapse(input$richnessMeasures, sep='\", \"')}\")"
+        )
+      ),
+      ")\n",
+      ifelse((input$richnessBoxplot >= 2),
+             "p <- p + geom_boxplot()\n",
+             ""),
+      ifelse((input$richnessBoxplot <= 2),
+             "p <- p + geom_point()\n",
+             ""),
+      "\n",
+      "plot(p)",
+      "\n",
+      "\n",
+      "# Tables\n",
+      glue("t <- estimate_richness(data"),
+      ifelse(
+        is.null(checkNull(input$richnessMeasures)),
+        "",
+        glue(
+          ", measures = c(\"{glue_collapse(input$richnessMeasures, sep='\", \"')}\")"
+        )
+      ),
+      ")\n",
+      "write.table(t, file = \"richness.tsv\", sep = \"\\t\", col.names = NA)"
     )
   })
   
@@ -565,6 +624,7 @@ shinyServer
   })
   
   output$richnessBUI <- renderUI({
+    validate(need(data16S(), ""))
     box(
       title = "Setting : " ,
       width = NULL,
-- 
GitLab