-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
167 lines (139 loc) · 7.73 KB
/
server.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
#setwd('/srv/shiny_server/umlsbrowser')
#deployApp()
rm(list = ls())
library(shiny)
library(dplyr)
library(DT)
umls <- dbConnect(drv=RSQLite::SQLite(),
dbname="umls_browser.sqlite3")
licenseCode <- < code read into here>
shinyServer(function(input, output) {
source('ui1.R') #login page
source('ui2.R') # UMLS page
options(DT.options = list(iDisplayLength = 100, scrollX = TRUE))
df<-NULL
output$page <- renderUI({ ui1 })
# code here from Untitled2
observeEvent(input$login,{
output$page <- renderUI({ ui1 })
z<-system(paste("perl", "umls_auth.pl",
paste0("'",input$user,"'"), paste0("'",input$password,"'")),intern=TRUE)
if (grepl("false",z[22])) {
#output$page <- renderUI({ ui1 })
renderText("Incorrect credentials")
}
if (grepl("true",z[22]))
{
output$page <- renderUI({ ui2 })
#output <- reactiveValues(table = NULL)
observeEvent(input$do2, {
if (input$rd == "exact"){
df<<-as.data.frame(dbGetQuery(umls,
paste0("SELECT DISTINCT CUI, SAB, CODE, STR FROM MRCONSO
WHERE STR ='", input$term ,"'",sep="")))
output$table<-renderDT({as.data.frame(dbGetQuery(umls,
paste0("SELECT DISTINCT CUI, SAB, CODE, STR FROM MRCONSO
WHERE STR ='", input$term ,"'",sep="")))
},class = "display nowrap compact",filter = "top",server=TRUE)
}
})
observeEvent(input$do0, {
inFile <- input$uploaded
dat<-read.csv(inFile$datapath,header=FALSE)
names(dat)<-"CODE"
con <- dbConnect(SQLite())
dbWriteTable(umls,"uploaded", dat,overwrite=TRUE)
if (input$rd == "exact"){
df<<-as.data.frame(dbGetQuery(umls,
paste0("SELECT DISTINCT c.CUI, c.SAB, a.CODE as MAPPED,b.CODE as ORIG, c.STR FROM uploaded b
left join MRCONSO a
on a.CODE = b.CODE
left join MRCONSO C
on a.CUI = c.CUI",sep="")))
output$table<-renderDT({as.data.frame(dbGetQuery(umls,
paste0("SELECT DISTINCT c.CUI, c.SAB, a.CODE as MAPPED,b.CODE as ORIG, c.STR FROM uploaded b
left join MRCONSO a
on a.CODE = b.CODE
left join MRCONSO C
on a.CUI = c.CUI",sep="")))
},class = "display nowrap compact",filter = "top",server=TRUE)
}
})
observeEvent(input$do1, {
if (input$rd == "exact"){
df<<-as.data.frame(dbGetQuery(umls,
paste0("SELECT DISTINCT CUI, SAB, CODE, STR FROM MRCONSO
WHERE CUI ='", input$code ,"'",sep="")))
output$table<-renderDT({as.data.frame(dbGetQuery(umls,
paste0("SELECT DISTINCT CUI, SAB, CODE, STR FROM MRCONSO
WHERE CUI ='", input$code ,"'",sep="")))
},class = "display nowrap compact",filter = "top",server=TRUE)
}
})
observeEvent(input$do2, {
if (input$rd == "CHD" || input$rd == "PAR" || input$rd == "SIB"){
df<<-as.data.frame(dbGetQuery(umls,
paste0("SELECT DISTINCT B.CUI2 as CUI, C.SAB, C.CODE, C.STR FROM MRCONSO A
INNER JOIN MRREL B ON A.CUI = B.CUI1
INNER JOIN MRCONSO C ON B.CUI2 = C.CUI
WHERE B.REL = '", input$rd ,"'","AND A.STR ='", input$term ,"'",sep="")))
output$table<-renderDT({as.data.frame(dbGetQuery(umls,
paste0("SELECT DISTINCT B.CUI2 as CUI, C.SAB, C.CODE, C.STR FROM MRCONSO A
INNER JOIN MRREL B ON A.CUI = B.CUI1
INNER JOIN MRCONSO C ON B.CUI2 = C.CUI
WHERE B.REL = '", input$rd ,"'","AND A.STR ='", input$term ,"'",sep="")))
},class = "display nowrap compact",filter = "top",server=TRUE)
}
})
#output$table <- renderDT({res()})
observeEvent(input$do1, {
if (input$rd == "CHD" || input$rd == "PAR" || input$rd == "SIB"){
df<<-as.data.frame(dbGetQuery(umls,
paste0("SELECT DISTINCT B.CUI2 as CUI, C.SAB, C.CODE, C.STR FROM MRCONSO A
INNER JOIN MRREL B ON A.CUI = B.CUI1
INNER JOIN MRCONSO C ON B.CUI2 = C.CUI
WHERE B.REL = '", input$rd ,"'","AND B.CUI1 ='", input$code ,"'",sep="")))
output$table<-renderDT({as.data.frame(dbGetQuery(umls,
paste0("SELECT DISTINCT B.CUI2 as CUI, C.SAB, C.CODE, C.STR FROM MRCONSO A
INNER JOIN MRREL B ON A.CUI = B.CUI1
INNER JOIN MRCONSO C ON B.CUI2 = C.CUI
WHERE B.REL = '", input$rd ,"'","AND B.CUI1 ='", input$code ,"'",sep="")))
#return(df)
},class = "display nowrap compact",filter = "top",server=TRUE)
}
})
observeEvent(input$do3, {
if (input$rd == "exact" || input$rd == "CHD" || input$rd == "PAR" || input$rd == "PAR"){
df<<-as.data.frame(dbGetQuery(umls, input$query,sep=""))
output$table<-renderDT({as.data.frame(dbGetQuery(umls, input$query,sep=""))
},class = "display nowrap compact",filter = "top",server=TRUE)
}
})
observeEvent(input$extension, {
if (input$extension == "csv"){
output$downloadData <- downloadHandler(
filename = function() {
paste(input$downloadData, "",".csv",sep="")
},
content = function(file) {
write.csv(df[input[["table_rows_all"]],],file,row.names=F)
}
)
}
else if (input$extension == "lst"){
output$downloadData <- downloadHandler(
filename = function() {
paste(input$downloadData, "",".lst",sep="")
},
content = function(file) {
fileConn<-file(file)
writeLines(paste0(df[input[["table_rows_all"]],c("STR")],"\tCUI=",df[input[["table_rows_all"]],c("CUI")],
"\tPREF=",df[input[["table_rows_all"]],c("STR")]), fileConn)
close(fileConn)
}
)
}
})
}
})
})