-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
96 lines (85 loc) · 2.95 KB
/
app.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
library(shiny)
library(VennDiagram)
library(stringr)
source("functions.R")
example_query<-scan_in("example_query")
example_reference<-scan_in("example_reference")
example_background<-scan_in("example_background")
u <- shinyUI(
fluidPage(
sidebarPanel(
textAreaInput('vec1', 'Query values (newline delimited)'),
textAreaInput('vec2', 'Reference values (newline delimited)'),
textAreaInput('vec3', 'Background values (newline delimited)'),
actionButton("run", "Run test"),
actionButton("reset", "Reset"),
actionButton("example", "Example")
),
mainPanel(
h3('Fisher test for enrichment'),
br(),
p("Test for enrichment of one list in another list, given a third, background list"),
p("Enter newline delimited values in the relevant boxes to the left"),
h3('Test result:'),
verbatimTextOutput("show_results"),
br(),
imageOutput("venn_diagram")
)
))
s <- shinyServer(function(input, output, session) {
# print contigency table and results
results<-eventReactive(input$run, {
query <- unlist(strsplit(input$vec1,"\n"))
ref <- unlist(strsplit(input$vec2,"\n"))
back<- unlist(strsplit(input$vec3,"\n"))
contingency<-contingency_table(query,ref,back)
fisher<-fisher_test(contingency)
results<-print_results(fisher)
cat("Contingency table: \n\n")
print(contingency)
cat("\n")
cat("Results: \n\n")
cat(results)
})
# set up venn diagram
venn<-eventReactive(input$run, {
outfile <- tempfile(fileext='.png')
png(outfile, width=400, height=300)
draw_venn(input$vec1, input$vec2, input$vec3)
dev.off()
list(src = outfile,
contentType = 'image/png',
width = 400,
height = 300,
alt = "")
})
# shownresults and venn diagram on clicking run
observeEvent(input$run, {
output$show_results<-renderPrint({
results()
})
output$venn_diagram <- renderImage({
venn()
})
})
# render empty text and plot blank on clicking reset
observeEvent(input$reset, {
output$show_results <- renderText({
})
updateTextInput(session, "vec1", value="")
updateTextInput(session, "vec2", value="")
updateTextInput(session, "vec3", value="")
output$venn_diagram <- plot.new()
dev.off()
})
# fill in inputs with example data on clicking example
observeEvent(input$example, {
output$show_results <- renderText({
})
updateTextInput(session, "vec1", value=example_query)
updateTextInput(session, "vec2", value=example_reference)
updateTextInput(session, "vec3", value=example_background)
})
}
)
shinyApp(ui = u, server = s)