-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
172 lines (164 loc) · 6.18 KB
/
server.R
File metadata and controls
172 lines (164 loc) · 6.18 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
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
library(shiny)
library(shinydashboard)
library(ggplot2)
#Server Logic
server <- function(input, output) {
# Point Graph ----
plot_data <- reactive(
data.frame(
prevalence = input$prevalence,
ppv = (((input$population*(input$prevalence/100))*(input$sensitivity/100))/(((input$population*(input$prevalence/100))*(input$sensitivity/100))+((input$population -(input$population*(input$prevalence/100)))-((input$population-(input$population*(input$prevalence/100)))*(input$specificity/100))))*100),
npv = (((input$population-(input$population*(input$prevalence/100)))*(input$specificity/100))/(((input$population - (input$population*(input$prevalence/100)))*(input$specificity/100))+((input$population*(input$prevalence/100))-((input$population*(input$prevalence/100))*(input$sensitivity/100))))*100)
)
) # End reactive for point plot data
observeEvent(
{
input$sensitivity
input$specificity
input$prevalence
},
(output$plot1 <- renderPlot
({
ggplot(
data = plot_data(),
aes(prevalence, ppv)
) +
geom_point(aes(x = prevalence, y = ppv),
color = "blue",
size = 4) +
geom_point(aes(x = prevalence, y = npv),
color = "red",
size = 4) +
labs(title = "Prevalence vs. Positive Predictive Value\nand Negative Predictive Value",
subtitle = "Note that PPV (blue) and NPV (red) go up and down based on prevalence",
x = "Prevalence",
y = "Positive Predictive Value"
) +
xlim(0,100)+
ylim(0,100)+
theme_bw()
})
)
) # End of ObserveEvent plot1
# Bar Plot ----
graph_data <- reactive(
data.frame(
"resultado" = as.factor(
c("True Positive", "False Negative", "False Positive", "True Negative")
),
"valor" = as.numeric(
c(
((input$population*(input$prevalence/100))*
(input$sensitivity/100)),
((input$population*(input$prevalence/100))-
((input$population*(input$prevalence/100))*(input$sensitivity/100))),
( (input$population - (input$population*(input$prevalence/100)))-
((input$population - (input$population*(input$prevalence/100)))*(input$specificity/100))),
((input$population - (input$population*(input$prevalence/100)))*
(input$specificity/100))
)
)
)
) # End reactive for bar plot data
observeEvent(
{
input$population
input$sensitivity
input$specificity
input$prevalence
},
(output$plot2 <- renderPlot({
ggplot(graph_data(),
aes(x = resultado,
y = valor,
fill = factor(resultado))
) +
geom_col(
color = "black"
) +
scale_fill_manual( values=c("red","red","blue","blue")) +
scale_y_continuous(labels = comma) +
labs(title="Number of People by Positive/Negative Result",
subtitle = "Data Updates With Inputs",
x = "Type of Result",
y = "Number of Results"
) +
theme_bw() +
theme(legend.position="none") +
theme(axis.text.x = element_text(angle=90, vjust=0.5, size=16))
})
)
)# End of ObserveEvent plot2
# Reactive expression to create data frame of all input values ----
sliderValues <- reactive({
data.frame(
Result = c(
"True Cases",
"True Non-Cases",
"True Positives",
"True Negatives",
"False Positives",
"False Negatives",
"Positive Predictive Value",
"Negative Predictive Value"
),
Value = as.character(c(
paste(
round(
input$population*
(input$prevalence/100), digits = 0)
),
paste(
round(
input$population -
(input$population*(input$prevalence/100)),
digits = 0
)
),
paste(
round(
(input$population*(input$prevalence/100))*
(input$sensitivity/100), digits = 0
)
),
paste(
round(
(input$population - (input$population*(input$prevalence/100)))*
(input$specificity/100), digits = 0
)
),
paste(
round(
(input$population - (input$population*(input$prevalence/100)))-
((input$population - (input$population*(input$prevalence/100)))*(input$specificity/100)), digits = 0
)
),
paste(
round(
(input$population*(input$prevalence/100))-
((input$population*(input$prevalence/100))*(input$sensitivity/100)), digits = 0
)
),
paste(round((((input$population*(input$prevalence/100))*
(input$sensitivity/100))/
(((input$population*(input$prevalence/100))*
(input$sensitivity/100))+((input$population - (input$population*(input$prevalence/100)))-
((input$population - (input$population*(input$prevalence/100)))*(input$specificity/100))))*100), digits = 1),"%"),
paste(
round(
(((input$population - (input$population*(input$prevalence/100)))*
(input$specificity/100))/(((input$population - (input$population*(input$prevalence/100)))*
(input$specificity/100))+((input$population*(input$prevalence/100))-
((input$population*(input$prevalence/100))*(input$sensitivity/100))))*100)
, digits = 1
),
"%"
)
)),
stringsAsFactors = FALSE)
})
# Show the values in an HTML table ----
output$values <- renderTable({
sliderValues()
})
}