-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathserver.R
More file actions
120 lines (79 loc) · 3.29 KB
/
server.R
File metadata and controls
120 lines (79 loc) · 3.29 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
library(caret)
library(shiny)
library(LiblineaR)
library(readr)
library(ggplot2)
load("RegularizedLogisticRegression.rda") # Load saved model
source("featureMapping.R") # a function for feature engineering.
# You can include data imputation, data manipulation, data cleaning,
# feature transformation, etc., functions
shinyServer(function(input, output) {
options(shiny.maxRequestSize = 800*1024^2) # This is a number which specifies the maximum web request size,
# which serves as a size limit for file uploads.
# If unset, the maximum request size defaults to 5MB.
# The value I have put here is 80MB
output$sample_input_data_heading = renderUI({ # show only if data has been uploaded
inFile <- input$file1
if (is.null(inFile)){
return(NULL)
}else{
tags$h4('Sample data')
}
})
output$sample_input_data = renderTable({ # show sample of uploaded data
inFile <- input$file1
if (is.null(inFile)){
return(NULL)
}else{
input_data = readr::read_csv(input$file1$datapath, col_names = TRUE)
colnames(input_data) = c("Test1", "Test2", "Label")
input_data$Label = as.factor(input_data$Label )
levels(input_data$Label) <- c("Failed", "Passed")
head(input_data)
}
})
predictions<-reactive({
inFile <- input$file1
if (is.null(inFile)){
return(NULL)
}else{
withProgress(message = 'Predictions in progress. Please wait ...', {
input_data = readr::read_csv(input$file1$datapath, col_names = TRUE)
colnames(input_data) = c("Test1", "Test2", "Label")
input_data$Label = as.factor(input_data$Label )
levels(input_data$Label) <- c("Failed", "Passed")
mapped = feature_mapping(input_data)
df_final = cbind(input_data, mapped)
prediction = predict(my_model, df_final)
input_data_with_prediction = cbind(input_data,prediction )
input_data_with_prediction
})
}
})
output$sample_prediction_heading = renderUI({ # show only if data has been uploaded
inFile <- input$file1
if (is.null(inFile)){
return(NULL)
}else{
tags$h4('Sample predictions')
}
})
output$sample_predictions = renderTable({ # the last 6 rows to show
pred = predictions()
head(pred)
})
output$plot_predictions = renderPlot({ # the last 6 rows to show
pred = predictions()
cols <- c("Failed" = "red","Passed" = "blue")
ggplot(pred, aes(x = Test1, y = Test2, color = factor(prediction))) + geom_point(size = 4, shape = 19, alpha = 0.6) +
scale_colour_manual(values = cols,labels = c("Failed", "Passed"),name="Test Result")
})
# Downloadable csv of predictions ----
output$downloadData <- downloadHandler(
filename = function() {
paste("input_data_with_predictions", ".csv", sep = "")
},
content = function(file) {
write.csv(predictions(), file, row.names = FALSE)
})
})