José Oliver Segura
july, 29th, 2020
This presentation shows the work done to build a shiny app that predicts Iris Species based on use input that can be found at https://joseo.shinyapps.io/IrisPrediction/.
This application uses sliders as a form of input for the petal/sepal width/length predictors and outputs back a Species prediction based on these inputs. It also includes boxplots of each of the predictors based on species and overlays on them the users' input.
The applicatin also includes a help/usage tab in order to ease their use.
In order to build this application, the following steps have been performed:
library(dplyr)
library(caret)
data(iris)
inTrain <- createDataPartition(iris$Species, p=0.75, list=FALSE)
trainingData <- iris[inTrain,]
testingData <- iris[-inTrain,]
rfModel <- train(Species ~ ., data=iris,method="rf")
save(rfModel,file="Test/data/model.rda")
predicted <- predict(rfModel,testingData)
mean(predicted==testingData$Species)
[1] 1
We can highlight two important factors on the shiny app
Loading the model outside the shinyServer function call
load(file="data/model.rda",.GlobalEnv)
Inside the shinyServer function call, using reactive programming to update our output
predictionText<- reactive({
newData <- data.frame(Sepal.Length=input$Sepal.Length,
...)
p <- predict(rfModel,newData)
levels(iris$Species)[p[1]]
})