-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.R
More file actions
299 lines (236 loc) · 12.4 KB
/
Copy pathserver.R
File metadata and controls
299 lines (236 loc) · 12.4 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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
server <- function(input, output) {
#########################################################################################################################################
#SUBJECT
typeA_prec <- reactive({
switch(input$typeA,
selectInput("typeB",h4("Precision about the type of the subject"),sub_categories[[input$typeA]],selected = "All"))
})
output$typeA_prec <- renderUI({typeA_prec()})
#########################################################################################################################################
#PREDICATE1
#SELECT INPUT FOR PREDICATE 1
output$uipredicat <- renderUI({predicat1()})
predicat1 <- reactive({
switch(input$typeB,
"All" = predicat1_typeA(),
selectInput("predicat",h4("Information you want about the subject"),predicates_categories[[input$typeB]],selected = "no"))
})
predicat1_typeA <- reactive({
switch(input$typeA,
selectInput("predicat",h4("Information you want about the subject"),predicates_categories[[input$typeA]])
)
})
#TYPE OF PLACE for located predicates
#SELECT INPUT WITH CITY/COUNTRY WHEN PLACE
output$typeofplace <- renderUI({placetype1()})
placetype1 <- reactive({
if (input$predicat == "no"){
selectInput("typeofplace",
h4("Precision"),
c("All"),selected = "All")}
#if the choose subject has its "unprecise_place" column filled by TRUE, you can specify the type of place
else if (predicates_dictionnary$unprecise_place[which(input$predicat == predicates_dictionnary$subtitle)] == TRUE){
selectInput("typeofplace",
h4("Precision"),
c("All","City","Country"),selected = "All")}
else{
selectInput("typeofplace",
h4("Precision"),
c("All"),selected = "All")}
})
#RANGE DATE for temporal predicates
output$uirangedatemin <- renderUI({rangedatemin()})
rangedatemin <- reactive({switch(grepl("date",input$predicat)|grepl("epoch",input$predicat),
"TRUE" = numericInput("rangedatemin", label = h4("minimum date (yyyy)"), value = "yyyy", min = NA, max = NA, step = NA,
width = NULL))})
output$uirangedatemax <- renderUI({rangedatemax()})
rangedatemax <- reactive({switch(grepl("date",input$predicat)|grepl("epoch",input$predicat),
"TRUE" = numericInput("rangedatemax", label = h4("maximum date (yyyy)"), value = "yyyy", min = NA, max = NA, step = NA,
width = NULL))})
#########################################################################################################################################
#PREDICATE2
#SELECT INPUT FOR PREDICATE 2
output$uipredicat2 <- renderUI({predicat2()})
predicat2 <- reactive({
switch(input$typeB,
"All" = predicat2_typeA(),
selectInput("predicat2",h4("Information you want about the subject"),predicates_categories[[input$typeB]],selected = "no")
)
})
predicat2_typeA <- reactive({
switch(input$typeA,
selectInput("predicat2",h4("Information you want about the subject"),predicates_categories[[input$typeA]])
)
})
#TYPE OF PLACE for located predicates
#SELECT INPUT WITH CITY/COUNTRY WHEN PLACE
output$typeofplace2 <- renderUI({placetype2()})
placetype2 <- reactive({
if (input$predicat2 == "no"){
selectInput("typeofplace2",
h4("Precision"),
c("All"),selected = "All")}
#if the choose subject has its "unprecise_place" column filled by TRUE, you can specify the type of place
else if (predicates_dictionnary$unprecise_place[which(input$predicat2 == predicates_dictionnary$subtitle)] == TRUE){
selectInput("typeofplace2",
h4("Precision"),
c("All","City","Country"),selected = "All")}
else{
selectInput("typeofplace2",
h4("Precision"),
c("All"),selected = "All")}
})
#RANGE DATE for temporal predicates
output$uirangedatemin2 <- renderUI({rangedatemin2()})
rangedatemin2 <- reactive({switch(grepl("date",input$predicat2)|grepl("epoch",input$predicat2),
"TRUE" = numericInput("rangedatemin2", label = h4("minimum date (yyyy)"), value = "yyyy", min = NA, max = NA, step = NA,
width = NULL))})
output$uirangedatemax2 <- renderUI({rangedatemax2()})
rangedatemax2 <- reactive({switch(grepl("date",input$predicat2)|grepl("epoch",input$predicat2),
"TRUE" = numericInput("rangedatemax2", label = h4("maximum date (yyyy)"), value = "yyyy", min = NA, max = NA, step = NA,
width = NULL))})
#########################################################################################################################################
#PLOT RESULTS
output$table <- renderDataTable({querying()})
querying <- eventReactive(input$goButton,{query_DBpedia(typeA = input$typeA,
typeAprec=input$typeB,
placesubject = input$placesubject,
namesubject=input$nameSubject,
exactsubject = input$exactsubject,
verb = input$predicat,
secondpredicate = input$nbpredicates,
verb2 = input$predicat2,
nameobject = input$nameObject,
exactobject = input$exactobject,
placeobject = input$typeofplace,
nameobject2 = input$nameObject2,
exactobject2 = input$exactobject2,
placeobject2 = input$typeofplace2,
mindate = input$rangedatemin,
maxdate = input$rangedatemax,
mindate2 = input$rangedatemin2,
maxdate2 = input$rangedatemax2,
nbresults = input$slider)})
#########################################################################################################################################
#EXPORT
output$downloadData <- downloadHandler(
filename = function() {
paste("dbpediaExtract", ".csv", sep = "")
},
content = function(file) {
write.csv(querying(), file, row.names = FALSE)
}
)
#########################################################################################################################################
#MAP
output$mymap <- renderLeaflet({
#if the subject is located
if (locatedsubject()){
plotmappreciseplace()}
else if (locatedobject1()){
#if the oject 1 and the object 2 are located
if(locatedobject2()){
plotmapobjects()}
#if only the object 1 is located
else {plotmapobject1()}
}
#if only the object 2 is located
else if (locatedobject2()){plotmapobject2()}
})
#if a column is called latitude, then the subject is located
locatedsubject <- reactive(
"latitude" %in% colnames(querying())
)
#if a column is called latitude_of_the_place, then the object1 is located
locatedobject1 <- reactive(
"latitude_of_the_place" %in% colnames(querying())
)
#if a column is called latitude_of_the_place2, then the object2 is located
locatedobject2 <- reactive(
"latitude_of_the_place2" %in% colnames(querying())
)
#plotting the map
#map for located subject
#(if the object is also located, only the subject is plot as more precise - an event is more precisely located than the country itself)
plotmappreciseplace <- reactive(
if (input$predicat == "no"){
leaflet(data = querying()) %>% addTiles() %>%
addMarkers(~as.numeric(longitude), ~as.numeric(latitude),label = ~as.character(querying()[[input$typeA]]),
popup = ~as.character(paste0(
strong("Name :"),
querying()[[input$typeA]])))
}
#if there are some information about the object in the table, it will be plot on the map too
else {
leaflet(data = querying()) %>% addTiles() %>%
addMarkers(~as.numeric(longitude), ~as.numeric(latitude),label = ~as.character(querying()[[input$typeA]]),
popup = ~as.character(paste0(
strong("Name :"),
querying()[[input$typeA]],
br(),
strong(input$predicat),":",
querying()[[input$predicat]])))
}
)
#map for located object1
plotmapobject1 <- reactive(
leaflet(data = querying()) %>% addTiles() %>%
addMarkers(~as.numeric(longitude_of_the_place),
~as.numeric(latitude_of_the_place),
label = ~as.character(querying()[[input$typeA]]),
popup = ~as.character(paste0(
strong("Name :"),
querying()[[input$typeA]],
br(),
strong(colnames(querying())[grep("place",colnames(querying()))[1]]),":",
querying()[[grep("place",colnames(querying()))[1]]])))
)
#map for located object2
plotmapobject2 <- reactive(
leaflet(data = querying()) %>% addTiles() %>%
addMarkers(~as.numeric(longitude_of_the_place2),
~as.numeric(latitude_of_the_place2),
label = ~as.character(querying()[[input$typeA]]),
popup = ~as.character(paste0(
strong("Name :"),
querying()[[input$typeA]],
br(),
strong(colnames(querying())[grep("place",colnames(querying()))[1]]),":",
querying()[[grep("place",colnames(querying()))[1]]])))
)
#map for both located object 1 and 2
#both are plotted, the object2 with another marker
#on the popup you have information on both object -whatever object 1 or 2 is clicked)
plotmapobjects <- reactive(
leaflet(data = querying()) %>% addTiles() %>%
addMarkers(~as.numeric(longitude_of_the_place),
~as.numeric(latitude_of_the_place),
label = ~as.character(querying()[[input$typeA]]),
popup = ~as.character(paste0(
strong("Name :"),
querying()[[input$typeA]],
br(),
strong(colnames(querying())[grep("place",colnames(querying()))[1]]),"(here):",
querying()[[grep("place",colnames(querying()))[1]]],
br(),
strong(colnames(querying())[grep("place",colnames(querying()))[2]]),":",
querying()[[grep("place",colnames(querying()))[2]]])))%>%
addMarkers(~as.numeric(longitude_of_the_place2),
~as.numeric(latitude_of_the_place2),
label = ~as.character(querying()[[input$typeA]]),icon=~coloredIcons["orange"],
popup = ~as.character(
paste0(
strong("Name :"),
querying()[[input$typeA]],
br(),
strong(colnames(querying())[grep("place",colnames(querying()))[1]]),":",
querying()[[grep("place",colnames(querying()))[1]]],
br(),
strong(colnames(querying())[grep("place",colnames(querying()))[2]]),"(here):",
querying()[[grep("place",colnames(querying()))[2]]])))
)
#function to choose a different marker (in case of 2 spatialized objects)
coloredIcons <- iconList(green = makeIcon("DATA/green_marker.png", iconWidth = 32),
red = makeIcon("DATA/red_marker.png", iconWidth = 32),
orange = makeIcon("DATA/orange_marker.png", iconWidth = 32))
}