-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReactive.R
180 lines (145 loc) · 5.55 KB
/
Reactive.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# ==== TASk - 5 reactivity ======================================================
# ==== global.R START ===========================================================
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
library(shiny)
library(ggplot2)
library(DT)
library(GeneBook)
gn <- read.csv('genes_names.csv')
g1 <- read.csv("g1.csv")
g2 <- read.csv("g2.csv")
g3 <- read.csv("g3.csv")
# ===================================================== global.R END ============
# ==== ui.R START ===============================================================
# Define UI for application
ui <- fluidPage(
# Application title
titlePanel("Gene Expression"),
# Sidebar
sidebarLayout(
# Sidebar Panel
sidebarPanel(
selectInput(
inputId ="G_groups",
label = "A- Choose Group to plot:",
choices = c("1- Genes down regulated in resistant while
up regulated in susceptible " = "g1",
"2- Genes down regulated in both resistant
and susceptible" = "g2",
"3- Genes up regulated in both resistant and
susceptible " = "g3"))
, # We need comma between each input
selectInput(
inputId = "My_dataset",
label = "B- Choose Gene ID to show it's full name:",
choices = as.character(gn$GeneID)),
selectInput(
inputId = "More_info",
label = "C- Documentation:",
choices = c('Introduction', 'Information', 'Help',
'References', 'Table-1','Table-2','Table-3'),
selected = "Information")
# ,
# submitButton(
# text = "Apply Changes",
# icon = icon("sliders"), # try: 'download', 'close', 'refresh', 'calendar', 'cog'
# width ='200px') # Replace with width ='80%'
),
# Main Panel
mainPanel(
downloadButton(
outputId = "downloadData",
label = "Download Data"),
plotOutput(
outputId = "myplot",
width = "100%",
height = "400px"),
verbatimTextOutput(
outputId = "odataset"),
uiOutput(
outputId = "odataset_link"),
uiOutput(
outputId = "text1")
)
)
)
# ===================================================== ui.R END ================
# ==== server.R START ===========================================================
# Define server logic
# To access any input use input$[inputId]
# ex. input$G_groups (the first select input value)
# To assign any output use output$[outputId] output$
# ex. output$myplot (assign the plot output)
server <- function(input, output) {
output$odataset <- renderPrint({
paste(input$My_dataset," = ", gn$Gene[gn$GeneID==input$My_dataset])
})
# using GeneBook library to construct a link to the gene database
abbreviation <- reactive((GeneCard_ID_Convert(input$My_dataset)))
# output for the odataset_link
output$odataset_link <- renderPrint({
tags$a(
href = paste(
"https://www.genecards.org/cgi-bin/carddisp.pl?gene=",
as.character(abbreviation()[1]),
sep = ''
),
as.character(abbreviation()[1])
)
})
full_file_name <-reactive(paste( input$G_groups, ".csv", sep = ""))
output$downloadData <- downloadHandler(
filename = full_file_name,
content = function(file){
write.csv(read.csv(full_file_name()), quote = FALSE,file)
} )
output$myplot = renderPlot({
g_x <- read.csv(full_file_name())
p <- ggplot(g_x, aes(x=Gene_ID, y=log(Relative_expression_levels),
fill=Resistant_or_Susceptible_strains)) +
geom_bar(stat="identity", position=position_dodge()) +
geom_errorbar(aes(ymin=log(Relative_expression_levels)-(SD/10),
ymax=log(Relative_expression_levels)+(SD/10)),width=.3,
position=position_dodge(.9))
p + scale_fill_brewer(palette="Paired")+
ggtitle(paste("Relative expression levels of candidate gene list","\n",
"expressed as mean fold difference between pre- and",
"\n", "post-infection ± standard deviation (SD) ")) +
guides(fill=guide_legend(title=NULL))
p$theme <- theme(axis.text.x = element_text(angle = 90, hjust = 1))
p$labels$x <- "Gene ID"
p$labels$y <- "Log (base 10) Relative Expression Levels"
p$labels$fill <- NULL
return(p)
})
# renderDT() from DT library is a replacement for Shiny renderDataTable()
output$datatable1 <- renderDT(datatable(g1, options = list(
lengthMenu = list(c(5, 15, -1), c('5', '15', 'All')),
pageLength = 5)
))
output$datatable2 <- renderDT(datatable(g2))
output$datatable3 <- renderDT(datatable(g3))
output$text1 <- renderUI({
if(input$More_info=="Introduction"){
includeHTML("introduction.html")
} else if(input$More_info=="Information"){
includeHTML("information.html")
} else if(input$More_info=="Help"){
includeHTML("help.html")
} else if(input$More_info=="Table-1"){
DTOutput('datatable1')
} else if(input$More_info=="Table-2"){
DTOutput('datatable2')
} else if(input$More_info=="Table-3"){
DTOutput('datatable3')
} else if(input$More_info=="References"){
includeHTML("references.html")
}
})
}
# ===================================================== server.R END ============
# Run the application
shinyApp(ui = ui, server = server)