-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
137 lines (111 loc) · 4.6 KB
/
app.R
File metadata and controls
137 lines (111 loc) · 4.6 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
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(ggplot2)
library(dplyr)
library(tidyr)
wd <- getwd()
setwd(wd)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Visualisation of Lifestyle Diseases by Age in the US population, 2005-2006"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput('visualise', 'Association between', choices = c("Obesity and Age", "Hypertension and Age")),
selectInput('gender', 'Gender', choices = c("All", "Male","Female","Both")),
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("plot")
)
),
# A new row for the data table
fluidRow(
column(width=12,
dataTableOutput("table"),
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
data_obesity <- read.csv(file=file.path("intermediates/data", "obesityTransformedData.csv"),header = TRUE)
data_obesity_all <- read.csv(file=file.path("intermediates/data", "obeseProbData.csv"),header = TRUE)
data_obesity_male <- read.csv(file=file.path("intermediates/data", "obeseMaleProbData.csv"),header = TRUE)
data_obesity_female <- read.csv(file=file.path("intermediates/data","obeseFemaleProbData.csv"),header = TRUE)
data_hypertension <- read.csv(file=file.path("intermediates/data","hypertensionTransformedData.csv"),header = TRUE)
data_hypertension_all <- read.csv(file=file.path("intermediates/data","hypertensionProbData.csv"),header = TRUE)
data_hypertension_male <- read.csv(file=file.path("intermediates/data","hypertensionMaleProbData.csv"),header = TRUE)
data_hypertension_female <- read.csv(file=file.path("intermediates/data","hypertensionFemaleProbData.csv"),header = TRUE)
visualise <- reactive({
input$visualise
})
gender <- reactive({
input$gender
})
output$plot <- renderPlot({
if(visualise() == "Hypertension and Age"){
if(gender() == "All"){
ggplot(data_hypertension_all, aes(x=age,y=hypertension_probability))+geom_line()+
xlab("age in years") +
ylab("Hypertension Probability")
}
else if(gender() == "Male"){
ggplot(data_hypertension_male, aes(x=age,y=male_hypertension_probability))+geom_line()+
xlab("age in years") +
ylab("Hypertension Probability in Males")
}
else if(gender() == "Female"){
ggplot(data_hypertension_female, aes(x=age,y=female_hypertension_probability))+geom_line()+
xlab("age in years") +
ylab("Hypertension Probability in Females")
}
else if(gender() == "Both"){
ggplot()+
geom_line(data = data_hypertension_male, aes(x=age,y=male_hypertension_probability),col="blue")+
geom_line(data = data_hypertension_female, aes(x=age,y=female_hypertension_probability),col="red")+
xlab("age in years") +
ylab("Hypertension Probability")
}
}
else if(visualise() == "Obesity and Age"){
if(gender() == "All"){
ggplot(data_obesity_all, aes(x=age,y=obesity_probability))+geom_line()+
xlab("age in years") +
ylab("Obesity Probability")
}
else if(gender() == "Male"){
ggplot(data_obesity_male, aes(x=age,y=male_obesity_probability))+geom_line()+
xlab("age in years") +
ylab("Obesity Probability in Males")
}
else if(gender() == "Female"){
ggplot(data_obesity_female, aes(x=age,y=female_obesity_probability))+geom_line()+
xlab("age in years") +
ylab("Obesity Probability in females")
}
else if(gender() == "Both"){
ggplot()+
geom_line(data = data_obesity_male, aes(x=age,y=male_obesity_probability),col="blue")+
geom_line(data = data_obesity_female, aes(x=age,y=female_obesity_probability),col="red")+
xlab("age in years") +
ylab("Obesity Probability")
}
}
})
output$table <- renderDataTable({
if(visualise() == "Hypertension and Age"){
data_hypertension}
else if(visualise() == "Obesity and Age"){
data_obesity}
})
}
# Run the application
shinyApp(ui = ui, server = server)