-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
51 lines (40 loc) · 1.25 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
library(data.table)
library(randomForest)
# Read in the RF model
model <- readRDS("model.rds")
shinyServer(function(input, output, session) {
# Input Data
datasetInput <- reactive({
df <- data.frame(
Name = c("Sepal Length",
"Sepal Width",
"Petal Length",
"Petal Width"),
Value = as.character(c(input$Sepal.Length,
input$Sepal.Width,
input$Petal.Length,
input$Petal.Width)),
stringsAsFactors = FALSE)
Species <- 0
df <- rbind(df, Species)
input <- transpose(df)
write.table(input,"input.csv", sep=",", quote = FALSE, row.names = FALSE, col.names = FALSE)
test <- read.csv(paste("input", ".csv", sep=""), header = TRUE)
Output <- data.frame(Prediction=predict(model,test), round(predict(model,test,type="prob"), 3))
print(Output)
})
# Status/Output Text Box
output$contents <- renderPrint({
if (input$submitbutton>0) {
isolate("Calculation complete.")
} else {
return("Server is ready for calculation.")
}
})
# Prediction results table
output$tabledata <- renderTable({
if (input$submitbutton>0) {
isolate(datasetInput())
}
})
})