-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
tempApp.R
77 lines (61 loc) · 2.73 KB
/
tempApp.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#this code still needs to be added to the respective UI/server documents
#it runs by itself
#formmating changes needed to center some of the components
#last thing is to determine how to highlight specific heatmap samples. Also need to link those colors to the barplot
library("shiny")
library("phyloseq")
data("GlobalPatterns")
data("esophagus")
#load preset dataset
loadOTUMatrix <- function(dataSetName) {
otuTable <- otu_table(get(dataSetName))
otuMatrix <- matrix(nrow = nrow(otuTable), ncol = 0)
otuMatrix <- apply(otuTable, 2, function(x) cbind(otuMatrix, x))
rownames(otuMatrix) <- rownames(otu_table(get(dataSetName)))
colnames(otuMatrix) <- colnames(otu_table(get(dataSetName)))
otuMatrix
}
otuMatrix <- loadOTUMatrix("GlobalPatterns")
ui <- fluidPage(
titlePanel("Alpha Diversity Metrics"),
sidebarLayout(position = "left",
sidebarPanel(
selectInput(inputId = "dataSelection", label = "Choose a Dataset", multiple = FALSE, choices = c("GlobalPatterns", "esophagus"), selected = "GlobalPatterns"),
checkboxGroupInput(inputId = "groupSelection", label = "Select Metrics", choiceNames = c("ACE", "Shannon", "Simpson", "InvSimpson", "Fisher"), choiceValues = c("ACE", "Shannon", "Simpson", "InvSimpson", "Fisher"))
),
mainPanel(
plotOutput(outputId = "phylo")
)
),
titlePanel("Alpha Diversity Summary"),
tableOutput("table"),
mainPanel(
sliderInput(inputId = "sample", label = "Slide to Move through The Samples", value = 1, step = 1, min = 1, max = length(colnames(otuMatrix)))
),
mainPanel(
fluidRow(
splitLayout(cellWidths = c("50%", "50%"), plotOutput(outputId = "heatmap"), plotOutput(outputId = "bar"))
)
)
)
server <- function(input, output) {
output$phylo <- renderPlot({
title <- "Alpha Diversity Metrics"
otuMatrix <- loadOTUMatrix(input$dataSelection)
plot_richness(get(input$dataSelection), measures = c("Observed", input$groupSelection))
})
output$heatmap <- renderPlot({
heatmap(otuMatrix, Colv = NA, Rowv = NA, scale = "row", labRow = FALSE)
})
output$bar <- renderPlot({
title <- "dfadfa"
barplot(otuMatrix[, input$sample], names.arg = rownames(otuMatrix), main = colnames(otuMatrix)[input$sample])
})
sdTable <- matrix(nrow = 2, ncol = length(colnames(otuMatrix)))
rownames(sdTable) <- c("Singleton", "Doubleton")
colnames(sdTable) <- colnames(otuMatrix)
sdTable[1,] <- apply(otuMatrix, 2, function(x) length(which(x == 1)))
sdTable[2,] <- apply(otuMatrix, 2, function(x) length(which(x == 2)))
output$table = renderTable(sdTable,rownames = TRUE )
}
shinyApp(ui = ui, server = server)