-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
129 lines (92 loc) · 4.16 KB
/
Copy pathserver.R
File metadata and controls
129 lines (92 loc) · 4.16 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
library(shiny)
library(googleVis)
library(reshape2)
sipri.plot <- function(data, country.var, value.var, tooltip.var, log = FALSE, regions = 'world'){
plot.data <- data[complete.cases(data),]
if(log == TRUE){
if(regions == 'world'){
plot.data$Log.Defence.Expenditure <- log(plot.data[,value.var] + 1)
return(gvisGeoChart(plot.data, country.var, colorvar = "Log.Defence.Expenditure",
options = list(height=500, width = 750,
colors="[\'blue', \'orange']",
region = regions)))
}else{
plot.data$Log.Defence.Expenditure <- log(plot.data[,value.var] + 1)
return(gvisGeoChart(plot.data, country.var, colorvar = "Log.Defence.Expenditure",
options = list(height=500, width = 750,
colors="[\'blue', \'orange']",
region = regions)))
}
end()
}
return(gvisGeoChart(plot.data, country.var, value.var,
options = list(height=500, width = 750,
colors="[\'blue', \'orange']",
region = regions)))
}
sipri.line.plot <- function(){
}
data <- read.csv("SIPRI data (current US$).csv", na.string=c(". .", "", "xxx"),
fileEncoding = "Windows-1252")
line.data <- read.csv('linechart data.csv', na.string=c(". .", "", "xxx"),
fileEncoding = "Windows-1252")
shinyServer(function (input, output) {
output$MapChart <- renderGvis({
data <- read.csv("SIPRI data (current US$).csv", na.string=c(". .", "", "xxx"),
fileEncoding = "Windows-1252")
SelectedYear <- as.numeric(input$Year)
SelectedRegion <- input$plot.region
temp <- as.data.frame(cbind(as.character(data[,1]), data[,SelectedYear]))
temp[,2] <- as.numeric(as.character(temp[,2]))
names(temp)[2] <- "defence.expenditure"
tooltip.spot <- which(names(temp)=="defence.expenditure")
data.frame(temp[1:tooltip.spot], defence.expenditure.html.tooltips = temp$defence.expenditure)
return(sipri.plot(temp, "V1", "defence.expenditure", "defence.expenditure.html.tooltips", log=input$Log.expend, regions = SelectedRegion))
})
output$LineChart <- renderGvis({
line.data <- read.csv('linechart data.csv', na.string=c(". .", "", "xxx"),
fileEncoding = "Windows-1252")
line.countries <- c(names(line.data[,-c(1, 174)]), "None")
test <- line.data
for(i in 2:173){
test[,i] <- line.data[,i]/line.data[,174]*100
}
######## define null values for country selection #########
if(input$Country1 == "None"){
country1 <- NULL
} else {
country1 <- input$Country1
}
if(input$Country2 == "None"){
country2 <- NULL
} else {
country2 <- input$Country2
}
if(input$Country3 == "None"){
country3 <- NULL
} else {
country3 <- input$Country3
}
if(input$Country4 == "None"){
country4 <- NULL
} else {
country4 <- input$Country4
}
####### plot line chart ###########
if(input$real.exp == F){
return(gvisLineChart(line.data[line.data$Year >= input$line.years[1] & line.data$Year <= input$line.years[2],
c('Year', country1, country2, country3, country4)],
options = list(height=500, width = 1000,
vAxes="[{title:'Defence Expenditure (Current US$m)'}]",
hAxes="[{title:'Year'}]")
))
} else {
return(gvisLineChart(test[test$Year >= input$line.years[1] & test$Year <= input$line.years[2],
c('Year', country1, country2, country3, country4)],
options = list(height=500, width = 1000,
vAxes="[{title:'Defence Expenditure (Constant 2009 US$m)'}]",
hAxes="[{title:'Year'}]")
))
}
})
})