From 03bf8701b3b80868afaea35b1a3b66789c0626fd Mon Sep 17 00:00:00 2001
From: Chanin Nantasenamat <51851491+dataprofessor@users.noreply.github.com>
Date: Sun, 26 Jan 2020 09:56:34 +0700
Subject: [PATCH] Add files via upload
---
shiny/app-numeric.R | 99 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 99 insertions(+)
create mode 100644 shiny/app-numeric.R
diff --git a/shiny/app-numeric.R b/shiny/app-numeric.R
new file mode 100644
index 0000000..035ec73
--- /dev/null
+++ b/shiny/app-numeric.R
@@ -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("
Input parameters"),
+ 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)
\ No newline at end of file