-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.R
183 lines (172 loc) · 4.71 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
library(shinyjs)
PAGE_TITLE <- "calculator"
# Define UI for application
ui <- fluidPage(
#header image
titlePanel(windowTitle = PAGE_TITLE,
title =
tags$a(href='https://www.columbiaobgyn.org/',
tags$img(src='columbia_obgyn_logo.png',width = "50%", height = "50%" ))),
h6(div(HTML("<em>\nSelect the model parameters below to calculate risk estimate:\n\n</em>"))),
useShinyjs(),
#create client side input form
sidebarLayout(
sidebarPanel(width = 5,
div(
id="form",
selectInput(inputId = "pscore",label = "Procedure Score", choices = c(0,1,2,'3+')),
sliderInput(inputId = 'age', label = 'Age', min=25, max=100,value=50, step=1, round=0),
selectInput(inputId = "pralbum",label = "Albumin", choices = c('<3.5','3.5-4','>4'), selected = '>4'),
selectInput(inputId = "asclas2",label = "ASA", choices = c(1,2,3,'4+'),selected = '1'),
checkboxInput(inputId = 'esurg',label = "Elective Surgery"),
selectInput(inputId = "ascites",label = "Ascites", choices = c('Yes','No'), selected = "No"),
selectInput(inputId = "bleed",label = "Bleeding disorder", choices = c('Yes','No'), selected = "No"),
actionButton("calc", "Calculate"),
verbatimTextOutput("final_val")
#div(img(src="nomogram.png",height = 200,wigth=400), style="text-align: center;")
)),
mainPanel()),
#footer
hr(),
tags$a(href='https://github.com/rptashkin/cumc_risk_calculator',
tags$img(src='github_logo.jpg',width = "5%", height = "5%" )),
tags$a(href='mailto:[email protected]',
tags$img(src='gmail_logo.png',width = "2.5%", height = "2.5%" , align="middle"))
)
# Define server logic
server <- function(input, output) {
paramValues <- reactive({
# Compose data frame
data.frame(
Parameter = c("pscore", "age","pralbum","asclas2","esurg","ascites","bleed"),
Selection = c(input$pscore,
input$age,
input$pralbum,
input$asclas2,
input$esurg,
input$ascites,
input$bleed),
stringsAsFactors=FALSE)
})
#estimate risk score based on input model parameters:
calculate <- function(pscore,age, pralbum, asclas, esurg, ascites, bleed) {
pointsPerLP = 66.21
intercept = -4.53792
LP= intercept
if (pscore==0){
pscoreBeta = 0
pscorePoints=0
}
else if(pscore==1){
pscoreBeta = 0.3459
pscorePoints=23
}
else if(pscore==2){
pscoreBeta = 0.8133
pscorePoints=54
}
else{
pscoreBeta = 1.5103
pscorePoints=100
}
if (age<50){
ageBeta = 0.2753
agePoints=18
}
else if(age>=50 & age<60){
ageBeta = 0
agePoints=0
}
else if(age>=60 & age<70){
ageBeta = 0.3320
agePoints=22
}
else if(age>=70 & age<80){
ageBeta = 0.5909
agePoints=39
}
else{
ageBeta = 0.8990
agePoints=60
}
if(esurg==TRUE){
esurgBeta=0
esurgPoints=0
}
else{
esurgBeta=0.5442
esurgPoints=36
}
if(ascites=="Yes"){
ascitesBeta=0.4593
ascitesPoints=30
}
else{
ascitesBeta=0
ascitesPoints=0
}
if(bleed=="Yes"){
bleedBeta=1.0031
bleedPoints=66
}
else{
bleedBeta=0
bleedPoints=0
}
if(pralbum=='<3.5'){
pralbumBeta = 0.6595
pralbumPoints=44
}
else if(pralbum=='3.5-4'){
pralbumBeta = 0.3501
pralbumPoints=23
}
else{
pralbumBeta = 0
pralbumPoints=0
}
if(asclas==1){
asclasBeta = 0
asclasPoints=0
}
else if(asclas==2){
asclasBeta = 0.2503
asclasPoints=17
}
else if(asclas==3){
asclasBeta = 0.4755
asclasPoints=31
}
else{
asclasBeta = 1.0624
asclasPoints=70
}
#calculate total points
totalPoints = (pscorePoints + agePoints + esurgPoints
+ ascitesPoints + bleedPoints + pralbumPoints + asclasPoints)
if(totalPoints==0){
LP= intercept
}
else{
LP = totalPoints /pointsPerLP+intercept
}
risk = exp(LP)/(1+exp(LP))
return(risk)
}
output$final_tbl <- renderTable({
if (input$calc == 0)
return()
isolate(paramValues())
})
output$final_val <- renderText({
if (input$calc == 0){
return()
}
else{
isolate(paste("Estimated Risk: ", round(calculate(input$pscore,input$age,
input$pralbum, input$asclas2, input$esurg, input$ascites, input$bleed),digits = 4)))
}
})
}
# Run the application
shinyApp(ui = ui, server = server)