-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
138 lines (127 loc) · 2.92 KB
/
Copy pathapp.R
File metadata and controls
138 lines (127 loc) · 2.92 KB
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
library(shiny)
library(shinysky)
library(glue)
library(Seurat)
library(ggplot2)
library(shinyWidgets)
df <- readRDS("runs_combined.rds")
all_gene_symbols <- unique(rownames(x = df))
default_genes <-
c(
'CFD',
'CLIC4',
'CSF1R',
'RGS10',
'MAG',
'PLP1',
'FGFR3',
'SOX9',
'GAD2',
'GAD1',
'CAMK2A',
'SLC17A6',
'SYN2',
'SNAP25'
)
ui <- fluidPage(
titlePanel("Cell Classes of the Intermediate Arcopallium"),
textInput.typeahead(
id = "gene_symbol",
placeholder = "Enter gene symbol",
local = data.frame(name = c(all_gene_symbols)),
valueKey = "name",
tokens = c(1:length(all_gene_symbols)),
template = HTML(
"<p class='repo-language'>{{info}}</p> <p class='repo-name'>{{name}}</p>"
)
),
actionBttn(
inputId = "add",
label = "Add",
style = "simple",
color = "primary",
size = "sm"
),
actionBttn(
inputId = "clear",
label = "Clear plot",
style = "bordered",
color = "primary",
size = "sm"
),
actionBttn(
inputId = "default",
label = "Cluster definitions",
style = "bordered",
color = "primary",
size = "sm"
),
downloadBttn(
outputId = "download",
label = "Download plot",
style = "bordered",
color = "primary",
size = "sm"
),
br(),
br(),
plotOutput(outputId = "dotplot"),
)
server <- function(input, output, session) {
# create reactive values object
myValues <- reactiveValues()
# when "Add gene" button is pressed, append to genelist
# condition checks that gene is not already in list, as duplicates broke
# the factor() function used within DotPlot()
observeEvent(input$add, {
if (!(isolate(input$gene_symbol) %in% isolate(myValues$genelist))) {
myValues$genelist <-
c(isolate(myValues$genelist),
isolate(input$gene_symbol))
}
})
observeEvent(input$default, {
myValues$genelist <- default_genes
})
# listen for either "add" or "default" button click
triggerplot <- reactive({
paste(input$add, input$default)
})
# build plot whenever "Add gene" button is clicked
plot_reactive <- eventReactive(triggerplot(), {
p <- DotPlot(df, features = myValues$genelist)
p <- p +
xlab("") +
ylab("Cluster") +
theme(axis.text.x = element_text(
angle = 45,
vjust = 0.9,
hjust = 1
))
})
# display plot
output$dotplot <- renderPlot({
if (input$add > 0 | input$default > 0) {
print(plot_reactive())
}
})
# download plot
output$download <- downloadHandler(
filename = "dotplot.png",
content = function(file) {
ggsave(
file,
plot = plot_reactive(),
height = 5,
width = (3 + length(isolate(
myValues$genelist
)) * 0.5)
)
}
)
# restart session (clear all input data)
observeEvent(input$clear, {
session$reload()
})
}
shinyApp(ui = ui, server = server)