-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.R
153 lines (142 loc) · 6.2 KB
/
ui.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
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
#
# UI file for the AccessHeart Shiny app.
#
library(shiny)
library(shinythemes)
library(shinyjs)
# Style for the loading page.
appCSS <- "
#loading-content {
position: absolute;
background: #2B3E50;
opacity: 0.9;
z-index: 100;
left: 0;
right: 0;
height: 100%;
text-align: center;
color: #FFFFFF;
}
"
# Set the Shiny theme.
shinyUI(fluidPage(
theme = shinytheme("superhero"),
# Include your Google Analytics script here for tracking.
tags$head(includeScript("google-analytics.js")),
useShinyjs(),
inlineCSS(appCSS),
tags$style(type = "text/css", "
.irs-min {color: #2B3E50;background: #2B3E50;}
.irs-max {color: #2B3E50;background: #2B3E50;}
"),
# Get geolocation
tags$script('
$(document).ready(function () {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
function onError (err) {Shiny.onInputChange("geolocation", false);}
function onSuccess (position) {
setTimeout(function () {
var coords = position.coords;
console.log(coords.latitude + ", " + coords.longitude);
Shiny.onInputChange("geolocation", true);
Shiny.onInputChange("lat", coords.latitude);
Shiny.onInputChange("long", coords.longitude);
}, 1100)
}
});
'),
# On application start, show loading screen while all the elements load.
div(
id = "loading-content",
h2("Loading AccessHeart...")
),
# Main application UI.
hidden(div(
id = "app-content",
# Title - shown on all pages.
titlePanel("AccessHeart Cardiovascular Disease Risk Calculator"),
hr(),
mainPanel(
# We're implementing the form as a set of divs which show and hide dynamically as the user moves through them.
div(
# The first tab is the user data input form, which collects age and blood pressure..
id = "form_page",
div("Welcome to the AccessHeart cardiovascular disease risk calculator. Please enter your information below:"),
hr(),
sliderInput("age", "Age (years)",18,80,40),
hr(),
div("Blood Pressure (mm Hg):"),
h2(textOutput("bp_all")),
sliderInput("ap_hi", "Systolic",0,200,120),
sliderInput("ap_lo", "Diastolic",0,200,80),
hr(),
# Get consent to store user data.
fluidRow(
column(3,checkboxInput("storedata","I consent to my anonymous data being stored for auditing purposes",value = TRUE)),
column(1,actionButton("submit", "Submit", class = "btn-primary"))
)
),
hidden(div(
# The second page shows the results of the CVD risk model. If their risk is under 10%, the
# application won't go further; if it's over 10%, they will be sent on to the quiz page.
id = "results_page",
div("Your risk of cardiovascular disease is:"),
h2(textOutput("riskpct")),
textOutput("riskrecc"),
hr(),
fluidRow(
column(2,offset = 0, actionButton("back1", "Back", class = "btn-primary")),
column(2,offset = 1, uiOutput("to_quiz"))
)
)),
hidden(div(
# The third page is a form for the user to describe their lifestyle, which is used for
# determining appropriate recommended actions.
id = "quiz_page",
# Allow them to select metric or US/imperial units for height and weight.
checkboxInput("metric","I use metric units"),
conditionalPanel(
condition = "input.metric == true",
sliderInput("mtheight", "Height (cm)",1,250,168),
sliderInput("mtweight", "Weight (kg)",1,200,84)
),
conditionalPanel(
condition = "input.metric == false",
sliderInput("usheight", "Height (in)",1,100,66),
sliderInput("usweight", "Weight (lbs)",1,500,185)
),
hr(),
# Questions about their lifestyle.
selectInput("chol", "Have you had your cholesterol checked in the past year?",c("Yes","No"), selected = "No"),
selectInput("glucose", "Have you had your blood sugar checked in the past year?",c("Yes","No"), selected =
"No"),
selectInput("smoke", "Do you currently use tobacco or nicotine?", c("Yes","No"), selected = "Yes"),
selectInput("active",
"Do you get at least 75 minutes of vigorous exercise or 150 minutes of moderate exercise each week?",
c("Yes", "No"), selected = "No"),
hr(),
# We take a guess at their zip code based on browser location, and allow them to enter a different ZIP
# if they prefer.
div("Enter your ZIP code for pricing in your area:"),
numericInput("usr_zip",label=NULL,value = 0,max= 99999),
hr(),
fluidRow(
column(2,offset = 0, actionButton("back2", "Back", class = "btn-primary")),
column(2,offset = 1, actionButton("recs_button","Get Recommendations", class = "btn-primary"))
)
)),
hidden(div(
# The last page displays personal recommendations with local costs.
id = "costs_page",
textOutput("recs_intro"),
tableOutput("risktable"),
textOutput("thanks"),
hr(),
actionButton("back3", "Back", class = "btn-primary")
)
)
)
)
)
)
)