-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathht_dss.R
131 lines (108 loc) · 3.64 KB
/
ht_dss.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
# Benjamin H Pepper
# B.H.Pepper@gmail.com
# https://www.linkedin.com/in/benjamin-pepper-62936714b/
library(shiny)
library(rlang)
library(pROC)
library(ggplot2)
library(fastDummies)
get_mod = function() {
return(readRDS('integrated_mod.RDS'))
}
get_dat = function() {
return(readRDS('integrated_dat.RDS'))
}
get_scores = function() {
return(readRDS('integrated_scores.RDS'))
}
get_labels = function() {
return(readRDS('integrated_labels.RDS'))
}
prob_f = function(mod, prototype, dat) {
prototype_dummy = dummy_cols(rbind(prototype,dat), remove_selected_columns = T,
remove_first_dummy=T)[1,]
preds = predict(mod$mod2, prototype_dummy, type='response')
return(preds)
}
dat = get_dat()
mod = get_mod()
scores = get_scores()
labels = get_labels()
types = unlist(lapply(dat, class))
names = names(types)
prototype = dat[1,]
widgets = list()
for(i in 1:length(types)) {
if (types[i] %in% c('numeric')) {
if (names[i] == 'AGE_AT_DIAGNOSIS')
{
low = round(min(dat[,names[i]], na.rm=T),0)
high = round(max(dat[,names[i]], na.rm=T),0)
widgets[[i]] = sliderInput(inputId = names[i],
h3(names[i]),
min = low,
max = high,
value = low,
step = 1)
}
else
{
low = round(min(dat[,names[i]], na.rm=T),2)
high = round(max(dat[,names[i]], na.rm=T),2)
widgets[[i]] = sliderInput(inputId = names[i],
h3(names[i]),
min = low,
max = high,
value = low,
step = round((high - low)/50,2))
}
} else if (types[i] %in% c('character', 'factor')) {
widgets[[i]] = selectInput(inputId = names[i],
h3(names[i]),
choices = unique(na.omit(dat[,names[i]])))
} else if (types[i] %in% c('integer')) {
low = min(dat[,names[i]], na.rm=T)
high = max(dat[,names[i]], na.rm=T)
widgets[[i]] = sliderInput(inputId = names[i],
h3(names[i]),
min = low,
max = high,
value = low,
step = 1)
}
}
ui = fluidPage(
titlePanel("Hormone Therapy Decision Support Tool"),
uiOutput("name"),
uiOutput("tab"),
sidebarLayout(
exec('sidebarPanel', !!!widgets),
mainPanel(
h3(textOutput('results'),
br(),
plotOutput(outputId = "ROCPlot"))
)
)
)
server = function(input, output) {
output$name <- renderUI({
tagList("By Benjamin H Pepper")
})
url <- a("github.com/BHPepper/HormoneTherapy-DSS-BreastCancer", href="https://github.com/BHPepper/HormoneTherapy-DSS-BreastCancer")
output$tab <- renderUI({
tagList("View code on GitHub:", url)
})
output$ROCPlot = renderPlot({
roc_obj = roc(labels, scores)
ggroc(roc_obj) + theme_minimal() + labs(title = paste0('ROC Curve for the Model - AUC: ',
round(auc(roc_obj), 3)))
})
output$results = renderText({
for(i in 1:length(types)) {
prototype[,names[i]] = input[[names[i]]]
}
probability = prob_f(mod, prototype, dat)
paste0('Predicted Probability of Hormone Therapy: ', round(probability, 3))
})
}
shinyApp(ui = ui, server = server)