-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
56 lines (50 loc) · 1.99 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
library(shiny)
library(leaflet)
library(ggplot2)
library(dplyr)
data1 <- data.table::fread("data.cvs")
names<-colnames(data1)
names[2]<-"year"
names[3]<-"month"
names[4]<-"day"
names[6]<-"country"
names[11]<-"attack_type"
names[12]<-"target_type"
names[14]<-"weapon_type"
colnames(data1)<-names
server <- function(input, output) {
output$summary <- renderText({
print("Change country and year bar to
review the geo-distribution of terrorism
of a country in that year.
Click pinpoint for more information about one terrorism activity.
The below charts shows the change of the number of
terrorism activity for a country since 1970.")
})
output$distPlot1 <- renderLeaflet({
dm <- data1 %>% filter(year == input$yaer, country == input$country)
leaflet(data = dm) %>%
addTiles() %>%
addMarkers(~longitude, ~latitude, popup = paste("Date:",dm$year,dm$month,dm$day,"<br>",
"Attact Type:",dm$attack_type,"<br>",
"Target:", dm$target_type,"<br>",
"Motive:",dm$motive,"<br>",
"Weapon Type:", dm$weapon_type
))
})
output$distPlot2 <- renderDataTable({
dm <- data1 %>% filter(year == input$yaer, country== input$country)
data2 <- dm %>% select(year, month, day, attack_type, target_type, weapon_type,city)
data2
},
options = list(lengthMenu = c(5, 10, 33), pageLength = 5))
output$linechart <- renderPlot({
specific_country <- data1 %>% filter(country == input$country) %>%
group_by(year) %>% dplyr::summarise(number = n())
ggplot(data = specific_country) +
geom_point(mapping = aes(x = year, y = number)) +
geom_smooth(mapping = aes(x = year, y = number)) +
labs(x = "Years", y = "Frequence")+
scale_x_continuous(limits=c(1970,2016),breaks=seq(1970,2016,2))
})
}