Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
dataprofessor authored Jan 26, 2020
1 parent dc6ff4c commit 03bf870
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions shiny/app-numeric.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
############################################
# Data Professor #
# http://youtube.com/dataprofessor #
# http://github.com/dataprofessor #
# http://facebook.com/dataprofessor #
# https://www.instagram.com/data.professor #
############################################

# Import libraries
library(shiny)
library(data.table)
library(randomForest)

# Read in the RF model
model <- readRDS("model.rds")


####################################
# User interface #
####################################

ui <- pageWithSidebar(

# Page header
headerPanel('Iris Predictor'),

# Input values
sidebarPanel(
HTML("<h3>Input parameters</h4>"),
numericInput("Sepal.Length", label = "Sepal Length", value = 5.0),
numericInput("Sepal.Width", label = "Sepal Width", value = 3.6),
numericInput("Petal.Length", label = "Petal Length", value = 1.4),
numericInput("Petal.Width", label = "Petal Width", value = 0.2),

actionButton("submitbutton", "Submit", class = "btn btn-primary")
),

mainPanel(
tags$label(h3('Status/Output')), # Status/Output Text Box
verbatimTextOutput('contents'),
tableOutput('tabledata') # Prediction results table

)
)

####################################
# Server #
####################################

server<- 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())
}
})

}

####################################
# Create the shiny app #
####################################
shinyApp(ui = ui, server = server)

0 comments on commit 03bf870

Please sign in to comment.