-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.R
More file actions
148 lines (147 loc) · 6.79 KB
/
Copy pathserver.R
File metadata and controls
148 lines (147 loc) · 6.79 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
BMI<-function(wght,hght) {
if (wght==0 | hght==0) return(NA)
else return(round(wght/(hght/100)^2,1))
}
classBMI<-function(bmic) {
if (is.na(bmic)) return ("")
else {
if (bmic<18.5) return("Your BMI is less than 18.5 you are considered UNDERWEIGHT")
if (bmic>=8.5 & bmic<24.9) return("Your BMI is in range 18.5 to 24.9 you are in HEALTHY WEIGHT RANGE")
if (bmic>=25 & bmic<29.9) return("Your BMI is in range 25 to 29.9 you are OVERWEIGHT")
if (bmic>=30) return("Your BMI is higher than 30 you are OBESE")
}
}
country<-function(ccode,state){
if (ccode=="USA") return (paste ("United States of America - ",state,sep=""))
else return(ISO_3166_1[ISO_3166_1$Alpha_3==ccode,4])
}
BMICrd<-function(ccode,gender){
temp<-subset(BMICrude,BMICrude$countrycode==ccode & BMICrude$sexdisplay==gender & BMICrude$displayvalue!="?")
if (nrow(temp)==0) return ("There are no data available for for your country")
else {
temp<-temp[order(-as.numeric(temp$yearcode)),]
return(paste(temp[1,"displayvalue"], ";",temp[1,"yearcode"]," Data",sep="" ))
}
}
BMICategories<-function(ccode){
temp<-subset(BMICat,BMICat$Code==ccode)
temp<-temp[order(temp$Year,decreasing=TRUE),c("Year","Indicator","Value")]
#temp<-subset(temp,temp$year==max(temp$year),select=c(2,5))
return(temp)
}
BMICatPlot<-function(ccode,gender,state){
temp<-subset(BMICat,BMICat$Code==ccode & grepl(paste("^BMI ",tolower(gender),"s",sep=""),as.character(BMICat$Indicator)))
if (nrow(temp)!=0) {
temp<-temp[order(temp$Year,decreasing=TRUE),]
temp<-temp[temp$Year==max(temp$Year),c(2,5,7)]}
if (nrow(temp)==0) {
temp<-subset(BMICat,BMICat$Code==ccode & grepl(paste("^BMI adults",sep=""),as.character(BMICat$Indicator)))
if (nrow(temp)!=0) {
temp<-temp[order(temp$Year,decreasing=TRUE),]
temp<-temp[temp$Year==max(temp$Year),c(2,5,7)]}
}
return(temp)
}
BMICatPlotYear<-function(ccode,gender,state){
temp<-subset(BMICat,BMICat$Code==ccode & grepl(paste("^BMI ",tolower(gender),"s",sep=""),as.character(BMICat$Indicator)))
if (nrow(temp)!=0) {
temp<-temp[order(temp$Year,decreasing=TRUE),]
temp<-temp[temp$Year==max(temp$Year),c(2,5,7)]
return(paste(unique(temp$Year),"Data"))}
if (nrow(temp)==0) {
temp<-subset(BMICat,BMICat$Code==ccode & grepl(paste("^BMI adults",sep=""),as.character(BMICat$Indicator)))
if (nrow(temp)==0) return("No Data!")
if (nrow(temp)!=0) {
temp<-temp[order(temp$Year,decreasing=TRUE),]
temp<-temp[temp$Year==max(temp$Year),c(2,5,7)]
return(paste(unique(temp$Year),"Data"))}
}
return(temp)
}
BMITrend<-function(ccode){
temp<-subset(BMICrude,BMICrude$countrycode==ccode,select=c("yearcode","numeric","sexdisplay"))
#if (nrow(temp)!=0) {
temp<-temp[order(c(temp$yearcode,temp$gender)),]
names(temp)<-c("Year","MeanBMI","Gender")
#}
return(temp)
}
USStatesPlot<-function(ccode,state){
if (ccode=="USA") temp<-subset(USStatesData,USStatesData$State==state)
else temp<-subset(USStatesData,USStatesData$State=="XXX")
return(temp)
}
USStatesLabel<-function(ccode,state){
if (ccode=="USA") return(state)
else return("")
}
library(shiny)
library(reshape2)
library(xlsx)
library(ISOcodes)
library(rCharts)
data(ISO_3166_1)
USState<-read.xlsx("data/USStates.xlsx",header=TRUE,sheetIndex=1)
USStatesData<-melt(USState,id.vars="State")
names(USStatesData)<-c("State","Indicator","Value")
BMICrude<-read.csv("data/dataverbose.csv")
BMICat<-read.csv("data/ObservationDataiijxxz.csv")
BMICat$Year<-as.numeric(format(as.Date(as.character(BMICat$Date),format="%d/%m/%Y"),"%Y"))
shinyServer(
function(input, output) {
output$oiweight <- renderPrint({input$weightM})
output$oiheight <- renderPrint({input$heightM})
output$oiBMI <- renderPrint({
input$goButton
isolate(BMI(input$weightM,input$heightM))
})
output$oiBMIclass<-renderText({
input$goButton
isolate(classBMI(BMI(input$weightM,input$heightM)))
})
output$oicountry<-renderText({
input$goButton
isolate(country(input$country,input$state))
})
output$oigender <- renderText({
input$goButton
isolate(input$gender)
})
output$oiBMIcrude <- renderText({
input$goButton
isolate(BMICrd(input$country,input$gender))
})
output$oiBMIcattable = renderDataTable({
input$goButton
isolate(BMICategories(input$country))
})
output$oiPlotYear = renderText({
input$goButton
isolate(BMICatPlotYear(input$country,input$gender,input$state))
})
output$Plot1 <- renderChart({
input$goButton
isolate(datap<-BMICatPlot(input$country,input$gender,input$state))
hb1 = hPlot(x = "Indicator", y = "Value", data = datap, type = "bar")
hb1$addParams(dom ='Plot1')
return(hb1)
})
output$Plot2 <- renderChart({
input$goButton
isolate(datat<-BMITrend(input$country))
hp1 <- hPlot(x = "Year", y = "MeanBMI",group="Gender", data = datat, type = "line")
hp1$addParams(dom ='Plot2')
return(hp1)
})
output$oiState<-renderText({
input$goButton
isolate(USStatesLabel(input$country,input$state))
})
output$Plot3 <- renderChart({
input$goButton
isolate(datau<-USStatesPlot(input$country,input$state))
hb2 = hPlot(x = "Indicator", y = "Value", data = datau, type = "bar")
hb2$addParams(dom ='Plot3')
return(hb2)
})
})