When I deploy the application and try to run it with given value on the web it gives me this error (Error in Analysis: object 'responses' not found) in my log and does not do the analysis part. I have been looking around for hours trying to fix it.
...
UI
#install.packages("shiny")
#install.packages("shinythemes")
Car_brand <-
read.csv('newbrand.csv',
header = FALSE)
Colors <-
read.csv('Colors.csv',
header = FALSE)
library(shiny)
library(shinythemes)
shinyUI(fluidPage(
theme=shinytheme("lumen"),
titlePanel("Used Car Price Calculator"),
sidebarLayout(
sidebarPanel(("Car Information"),
textInput("Miles", "Mileage on Car", ""),
textInput("Year", "Year of Car", ""),
textInput("City", "City gas Milage", ""),
textInput("Highway", "Highway gas Milage", ""),
textInput("Curbwieght", "Curbwieght of Car", ""),
textInput("HP", "HorsePower of Car", ""),
textInput("RPM", "RPM of Car", ""),
selectInput("Style", "Style of car",c("Sedan","SUV","Wagon","Hatchback"),selectize = TRUE),
selectInput("Brand", "Select the Brand", c(Car_brand), selectize = TRUE),
selectInput(
"Drivetype",
"Select the DriveType",
c("AWD", "RWD", "4WD", "FWD"),
selectize = TRUE
),
selectInput(
"Turbo",
"Select the Turbo type",
c("None", "Supercharged", "Turbocharged"),
selectize = TRUE
),
selectInput("Color", "Select the Color", c(Colors), selectize = TRUE),
actionButton("submit", "Submit")
),
mainPanel(tabsetPanel(
type = "tab",
tabPanel("Price", h3(textOutput("Car_price"), align = "center")),
tabPanel("Summary", verbatimTextOutput("sum")),
tabPanel("Data",tableOutput("frame")),
tabPanel("Model",h4(textOutput("models"),align="center"))
))
)
))
Server
library(shiny)
shinyServer(function(input,output){
counter <- reactiveValues(i = 0)
observeEvent( input$submit,{ # check if the action button is clicked
counter$i <- counter$i + 1
})
fields <- c("Miles","Year","City","Highway","Curbwieght","HP","RPM","Brand","Drivetype","Turbo","Color","Style")
Mile<- reactive({
Mile<- sapply(fields, function(x) input[[x]])
})
observeEvent(input$submit, {
saveData(Mile())
})
saveData <- function(data) {
data <- as.data.frame(t(data))
if (exists("Miles")) {
responses <<- rbind(responses, data)
} else {
responses<<- data
}
}
price<-eventReactive(input$submit,{
source("Regression model.R")
as.double(as.character(
unlist((Analysis(responses[counter$i,-13]))[2])))
})
model<-eventReactive(input$submit,{
source("Regression model.R")
(Analysis(responses[counter$i,-13]))[1]
})
Sums<-eventReactive(input$submit,{
source("Summary.R")
Sum(responses[counter$i,-13])
})
tab<-eventReactive(input$submit,{
source("Dataframe.R")
data_frames(responses[counter$i,-13])
})
output$Car_price<-renderPrint({
price()
})
output$sum<-renderPrint({
Sums()
})
output$frame<-renderTable({
tab()
})
output$models<-renderPrint({
model()
})
})