-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
228 lines (214 loc) · 9.42 KB
/
app.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
library(fresh)
mytheme <- create_theme(
adminlte_color(
light_blue = "#434C5E"
),
adminlte_sidebar(
width = "400px",
dark_bg = "#D8DEE9",
dark_hover_bg = "#81A1C1",
dark_color = "#2E3440"
),
adminlte_global(
content_bg = "#FFF",
box_bg = "#D8DEE9",
info_box_bg = "#D8DEE9"
)
)
library(shiny)
library(shinydashboard)
library(tidymodels)
library(tidyverse)
library(ranger)
model <- readr::read_rds("model.rds")
ui <- dashboardPage(
dashboardHeader(title = "Functional Impairment Risk Calculator"),
dashboardSidebar(
menuItem(
"Functional Impairment",
tabName = "func_tab"
),
disable = TRUE
),
dashboardBody(
use_theme(mytheme),
tags$head(tags$style(HTML(
'.abovetext {
line-height: 20px;
text-align: center;
font-family: "Arial";
padding: 0 15px;
color: white;
font-size: 1em;
}
@media (min-width: 1200px) {
.myClass {
line-height: 20px;
text-align: center;
font-family: "Arial";
padding: 0 15px;
color: white;
font-size: x-large
}
}
'))),
tags$script(HTML('
$(document).ready(function() {
$("header").find("nav").append(\'<span class="abovetext">Authors: Kyara Rodrigues Aguiar, Bruno Braga Montezano, Jacson Gabriel Feiten, Karen Jansen, Ives Cavalcante Passos.<br> This application should only be used for educational and research purposes.</span>\');
})
')),
tabItem(
tabName = "func_tab",
box(valueBoxOutput("func_prediction")),
box(selectInput("abep3_t1",
label = "Socioeconomic Status",
choices = list("Upper" = "X1", "Middle" = "X2", "Lower" = "X3"))),
box(selectInput("estano_t1",
label = "Currently studying",
choices = list("No" = "X0", "Yes" = "X1"))),
box(selectInput("religdic_t1",
label = "Has a religion",
choices = list("No" = "X0", "Yes" = "X1"))),
box(selectInput("escol_t1",
label = "Education",
choices = list("Incomplete high school" = "X1",
"Complete high school" = "X2",
"Complete higher education" = "X3"))),
box(selectInput("pais_doencapsi",
label = "Parental psychiatric disease",
choices = list("No" = "X0", "Yes" = "X1"))),
box(selectInput("medpsi",
label = "Psychiatric medication",
choices = list("No" = "X0", "Yes" = "X1"))),
box(selectInput("internacao_vida",
label = "Lifetime psychiatric hospitalization",
choices = list("No" = "X0", "Yes" = "X1"))),
box(selectInput("trabatu_t1",
label = "Currently working",
choices = list("No" = "X0", "Yes" = "X1"))),
box(selectInput("trat_t1",
label = "Psychological or psychiatric treatment",
choices = list("No" = "X0", "Yes" = "X1"))),
box(selectInput("interr_t1",
label = "Interrupted treatment before completion",
choices = list("No" = "X0", "Yes" = "X1"))),
box(selectInput("pais_faleceu",
label = "Parents passed away",
choices = list("No" = "X0", "Yes" = "X1"))),
box(selectInput("aldtenta_t1",
label = "Knows someone who tried suicide",
choices = list("No" = "X0", "Yes" = "X1"))),
box(selectInput("distat_t1",
label = "Current dysthymia",
choices = list("No" = "X0", "Yes" = "X1"))),
box(selectInput("agoraat_t1",
label = "Current agoraphobia",
choices = list("No" = "X0", "Yes" = "X1"))),
box(selectInput("fobsoa_t1",
label = "Current social anxiety disorder",
choices = list("No" = "X0", "Yes" = "X1"))),
box(selectInput("panico_lifetime",
label = "Lifetime panic disorder",
choices = list("No" = "X0", "Yes" = "X1"))),
box(selectInput("srq3_t1",
label = "SRQ Item 3",
choices = list("No" = "X0", "Yes" = "X1"))),
box(sliderInput("somabdi_t1",
label = "Beck Depression Inventory score",
min = 0, max = 100, value = 10)),
box(sliderInput("somasrq_t1",
label = "Self-Regulation Questionnaire score",
min = 0, max = 100, value = 10)),
box(sliderInput("abuso_emocional",
label = "Emotional abuse CTQ domain score",
min = 0, max = 100, value = 10)),
box(sliderInput("abuso_fisico",
label = "Physical abuse CTQ domain score",
min = 0, max = 100, value = 10)),
box(sliderInput("abuso_sexual",
label = "Sexual abuse CTQ domain score",
min = 0, max = 100, value = 10)),
box(sliderInput("neg_emocional",
label = "Emotional neglect CTQ domain score",
min = 0, max = 100, value = 10)),
box(sliderInput("neg_fisica",
label = "Physical neglect CTQ domain score",
min = 0, max = 100, value = 10)),
box(selectInput("any_ilicit_drug",
label = "Any illicit drug use",
choices = list("No" = "No", "Yes" = "Yes")))
)
)
)
server <- function(input, output) {
output$func_prediction <- renderValueBox({
prediction <- predict(
model,
tibble("abep3_t1" = input$abep3_t1,
"estano_t1" = input$estano_t1,
"religdic_t1" = input$religdic_t1,
"escol_t1" = input$escol_t1,
"pais_doencapsi" = input$pais_doencapsi,
"medpsi" = input$medpsi,
"internacao_vida" = input$internacao_vida,
"trabatu_t1" = input$trabatu_t1,
"trat_t1" = input$trat_t1,
"interr_t1" = input$interr_t1,
"pais_faleceu" = input$pais_faleceu,
"aldtenta_t1" = input$aldtenta_t1,
"distat_t1" = input$distat_t1,
"agoraat_t1" = input$agoraat_t1,
"fobsoa_t1" = input$fobsoa_t1,
"panico_lifetime" = input$panico_lifetime,
"srq3_t1" = input$srq3_t1,
"somabdi_t1" = input$somabdi_t1,
"somasrq_t1" = input$somasrq_t1,
"abuso_emocional" = input$abuso_emocional,
"abuso_fisico" = input$abuso_fisico,
"abuso_sexual" = input$abuso_sexual,
"neg_emocional" = input$neg_emocional,
"neg_fisica" = input$neg_fisica,
"any_ilicit_drug" = input$any_ilicit_drug)
)
prediction_prob <- predict(
model,
tibble("abep3_t1" = input$abep3_t1,
"estano_t1" = input$estano_t1,
"religdic_t1" = input$religdic_t1,
"escol_t1" = input$escol_t1,
"pais_doencapsi" = input$pais_doencapsi,
"medpsi" = input$medpsi,
"internacao_vida" = input$internacao_vida,
"trabatu_t1" = input$trabatu_t1,
"trat_t1" = input$trat_t1,
"interr_t1" = input$interr_t1,
"pais_faleceu" = input$pais_faleceu,
"aldtenta_t1" = input$aldtenta_t1,
"distat_t1" = input$distat_t1,
"agoraat_t1" = input$agoraat_t1,
"fobsoa_t1" = input$fobsoa_t1,
"panico_lifetime" = input$panico_lifetime,
"srq3_t1" = input$srq3_t1,
"somabdi_t1" = input$somabdi_t1,
"somasrq_t1" = input$somasrq_t1,
"abuso_emocional" = input$abuso_emocional,
"abuso_fisico" = input$abuso_fisico,
"abuso_sexual" = input$abuso_sexual,
"neg_emocional" = input$neg_emocional,
"neg_fisica" = input$neg_fisica,
"any_ilicit_drug" = input$any_ilicit_drug),
type = "prob"
) %>%
gather() %>%
arrange(desc(value)) %>%
slice(1) %>%
select(value)
prediction_color <- if_else(prediction$.pred_class == "Yes", "red", "green")
valueBox(
value = paste0(round(100*prediction_prob$value, 0), "%"),
subtitle = paste0("Functional impairment: ", prediction$.pred_class),
color = prediction_color
)
})
}
shinyApp(ui, server)