-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
81 lines (62 loc) · 2.38 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
# 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
#
library(shiny)
source('fertility_utils.R')
if (!require(stringr)) {
install.packages("stringr")
}
if (!require(gbm)) {
install.packages("gbm")
}
if (!require(pROC)) {
install.packages("pROC")
}
# Load random forest model of fertility from file
model <- readRDS("rf_Fit1.Rds")
shinyServer(function(input, output) {
# Normalize Input to match data format
normInput <- reactive({ normalizeInput(input) })
# Prepare user input for prediction to fit data frame in model for predict()
p.input <- eventReactive(eventExpr = input$submit, {h <- do.call(cbind, lapply(normInput(), as.data.frame))
names(h) <- names(normInput())
h
})
# Create Output
output$prediction <- renderText({
paste0(
# # For debugging only:
# "User inputs: \n",
# "\n",
# "Season: ", input$season, "\n",
# "Age:", input$age, "\n",
# "Diseases: ", input$diseases, "\n",
# "Trauma: ", input$trauma, "\n",
# "Surgery: ", input$surgery, "\n",
# "Fevers: ", input$fevers, "\n",
# "Alcohol: ", input$alcohol, "\n",
# "Smoking: ", input$smoking, "\n",
# "Sitting: ", input$sitting, "\n",
# "\n",
# "\n",
# "Normalized inputs: \n",
# "\n",
# "Season: ", normInput()$season, "\n",
# "Age: ", normInput()$age, "\n",
# "Diseases: ", normInput()$diseases, "\n",
# "Trauma: ", normInput()$trauma, "\n",
# "Surgery: ", normInput()$surgery, "\n",
# "Fevers: ", normInput()$fevers, "\n",
# "Alcohol: ", normInput()$alcohol, "\n",
# "Smoking: ", normInput()$smoking, "\n",
# "Sitting: ", normInput()$sitting, "\n",
# "\n",
switch(as.character( predict( model, p.input() ) ),
"N" = "Normal",
"O" = "Altered"
)
)
})
})