-
Notifications
You must be signed in to change notification settings - Fork 12
/
server.R
157 lines (121 loc) · 4.49 KB
/
server.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
# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com
#
gg2fig <- function(gg) {
gg.fig <- gg2list(gg)
gg.fig.layout <- gg.fig$kwargs$layout
gg.fig.data <- gg.fig$""
list(
data=list(gg.fig.data),
layout=gg.fig.layout
)
}
shinyServer(function(input, output) {
observe({
set.seed(1)
knn.pred <- knn(data.frame(train.X[,input$checkGroup]),
data.frame(test.X[,input$checkGroup]),
train.Y, k = input$k)
output$value <- renderText({ paste("Classification Error = ",ce(test.Y,knn.pred)) })
output$confusionMatrix <- renderDataTable({
# modify this to show title - confusion matrix
# /false positive/positive false negative/negative
true.positive <- sum(knn.pred == "positive" & test.Y == "positive")
false.positive <- sum(knn.pred == "negative" & test.Y == "positive")
true.negative <- sum(knn.pred == "negative" & test.Y == "negative")
false.negative <- sum(knn.pred == "positive" & test.Y == "negative")
row.names <- c("Prediction - FALSE", "Prediction - TRUE" )
col.names <- c("Reference - FALSE", "Reference - TRUE")
cbind(Outcome = row.names, as.data.frame(matrix(
c(true.negative, false.negative, false.positive, true.positive) ,
nrow = 2, ncol = 2, dimnames = list(row.names, col.names))))
}, options = table.settings
)
})
observe({
input_feature_x <- as.symbol(input$featureDisplay_x)
input_feature_y <- as.symbol(input$featureDisplay_y)
output$distPlotA <- renderGraph({
# plot distribution of selected feature
ggdistPlotA <- ggplot(ds, aes_string(x = input$featureDisplay_x,
fill = "factor(num)")) +
geom_histogram(position = "dodge") +
labs(x = input$featureDisplay_x,
y = "Count") + fte_theme() +
scale_fill_manual(guide = F,values=c("#7A99AC", "#E4002B"))
# convert plot details to list
# for plotly
fig <- gg2list(ggdistPlotA)
data <- list()
for(i in 1:(length(fig)-1)){data[[i]]<-fig[[i]]}
layout <- fig$kwargs$layout
layout$annotations <- NULL # Remove the existing annotations (the legend label)
# hide legend
layout$showlegend = FALSE
list(
list(
id="distPlotA",
task="newPlot",
data=data,
layout=layout
)
)
})
output$distPlotB <- renderGraph({
ggdistPlotB <- ggplot(ds, aes_string(input$featureDisplay_y,
fill = "factor(num)")) +
geom_histogram(position = "dodge") +
labs(x = input$featureDisplay_y,
y = "Count") + fte_theme() +
scale_fill_manual(guide = F,values=c("#7A99AC", "#E4002B"))
# convert plot details to list
# for plotly
fig <- gg2list(ggdistPlotB)
data <- list()
for(i in 1:(length(fig)-1)){data[[i]]<-fig[[i]]}
layout <- fig$kwargs$layout
layout$annotations <- NULL # Remove the existing annotations (the legend label)
# hide legend
layout$showlegend = FALSE
list(
list(
id="distPlotB",
task="newPlot",
data=data,
layout=layout
)
)
})
output$ScatterPlot <- renderGraph({
# plot selected features against one another
ggscatter <- ggplot(ds, aes_string(x = input$featureDisplay_x,
y = input$featureDisplay_y,
color = "factor(num)")) +
geom_point(size = 8, position = position_jitter(w = 0.1, h = 0.1)) +
labs(x = input$featureDisplay_x,
y = input$featureDisplay_y) +
fte_theme() +
scale_color_manual(name = "Heart Disease",values=c("#7A99AC", "#E4002B"))
# convert plot details to list
# for plotly
fig <- gg2list(ggscatter)
data <- list()
for(i in 1:(length(fig)-1)){data[[i]]<-fig[[i]]}
layout <- fig$kwargs$layout
layout$annotations <- NULL # Remove the existing annotations (the legend label)
# place legend to the right of the plot
layout$legend$x <- 100
layout$legend$y <- 1
list(
list(
id="ScatterPlot",
task="newPlot",
data=data,
layout=layout
)
)
})
})
})