I have a shiny chunk that takes a CSV user input from a file. The file is then used to create a linear regression model. However, when the model is returned, I only see the table column of the value "Class", and not the model itself. Does anyone know why that might be?
Upload CSV File:
ui <- fluidPage(
titlePanel("Upload Transaction Data Set"),
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv"))
),
mainPanel(
tableOutput("prediction")
)
)
)
Apply server code to take the CSV input, and then output the model:
server = function(input,output){
df = reactive({
req(input$file1)
read.csv(file = input$file1$datapath)
})
#Perform Regression
output$prediction = renderTable({
req(df())
set.seed(2)
split <- sample.split(thedata, SplitRatio=0.7)
df <- subset(thedata, split=TRUE)
Actual <- subset(thedata, split=FALSE)
model = lm(Class ~.,data = df())
prediction <- predict(model, Actual)
plot.new()
#plot(Actual$Class,type = "l",lty= 1.8,col = "red")
lines(prediction, type = "l", col = "blue")
plot(prediction,type = "l",lty= 1.8,col = "blue")
predict_df = data.frame(Class = prediction)
output_df = cbind(predict_df)
return(output_df)
})
}
shinyApp(ui,server)