rarefactionCurve-server.R 1.85 KB
Newer Older
Cedric Midoux's avatar
Cedric Midoux committed
1
output$rarefactionCurveUI <- renderUI({
2
  validate(need(physeq(), ""))
Cedric Midoux's avatar
Cedric Midoux committed
3
4
5
6
7
8
9
10
11
12
13
  box(
    title = "Setting : " ,
    width = NULL,
    status = "primary",
    checkboxInput("rarefactionMin", label = "Show min sample threshold", value = FALSE),
    textInput("rarefactionTitle",
              label = "Title : ",
              value = "Rarefaction curves"),
    selectInput(
      "rarefactionColor",
      label = "Color : ",
14
      choices = c("..." = 0, sample_variables(physeq()))
Cedric Midoux's avatar
Cedric Midoux committed
15
16
17
18
    ),
    selectInput(
      "rarefactionLabel",
      label = "Label : ",
19
      choices = c("..." = 0, sample_variables(physeq()))
Cedric Midoux's avatar
Cedric Midoux committed
20
21
22
23
    ),
    selectInput(
      "rarefactionGrid",
      label = "Subplot : ",
24
25
      choices = c("..." = 0, sample_variables(physeq()))
    )
Cedric Midoux's avatar
Cedric Midoux committed
26
27
28
  )
})

29
30
31
32
33
34
35
36
output$rarefactionCurve <- metaRender2(renderPlot, {
  validate(need(physeq(), "Requires an abundance dataset"))
  data <- physeq()

  rarefactionMin <- if (input$rarefactionMin) {
    metaExpr({
      geom_vline(xintercept = min(sample_sums(data)), color = "gray60")
    })
Cedric Midoux's avatar
Cedric Midoux committed
37
  }
38
39
40
  
  rarefactionGrid <- if (!is.null(checkNull(input$rarefactionGrid))) {
    metaExpr({
Cedric Midoux's avatar
Cedric Midoux committed
41
      facet_grid(..(paste(".", "~", input$rarefactionGrid)))
42
    })
Cedric Midoux's avatar
Cedric Midoux committed
43
44
  }
  
45
46
47
48
49
50
51
52
53
54
55
56
  metaExpr({
    p <- ggrare(
      physeq = data,
      step = 100,
      color = ..(checkNull(input$rarefactionColor)),
      label = ..(checkNull(input$rarefactionLabel)),
      se = FALSE
      )
    p <- p + ..(rarefactionMin)
    p <- p + ..(rarefactionGrid)
    p + ggtitle(..(input$rarefactionTitle))
  })
Cedric Midoux's avatar
Cedric Midoux committed
57
})
58
59
60
61
62
63
64
65
66
67
68
69
70

observeEvent(input$rarefactionCurve_output_code,
             {
               displayCodeModal(
                 expandChain(
                   quote(library(phyloseq)),
                   quote(library(phyloseq.extended)),
                   "# Replace `data` with you own data.",
                   output$rarefactionCurve()
                 )
               )
             }
)