Please see code below. I get the error: Warning: Error in UseMethod: no applicable method for 'predict' applied to an object of class "c('reactiveExpr', 'reactive', 'function')"
library(shiny)
library(ggplot2)
library(caret)
# Define server logic required to draw a histogram
function(input, output, session) {
output$data <- renderTable({
mtcars[, c(input$variable), drop = FALSE]
}, rownames = TRUE)
output$data2 <- renderTable({
mtcars[, c(input$variable2), drop = FALSE]
}, rownames = TRUE)
output$summary <- renderText({
paste("SUMMARY STATISTICS")
})
output$sum <- renderTable({
summary(mtcars)
})
model <- reactive({
lm(mtcars[, c(input$variable)] ~ mtcars[ , c(input$variable2)], data = mtcars)
})
output$reg <- renderText({
paste("REGRESSION COEFFICIENTS AND RESIDUALS")
})
output$coef <- renderTable({
as.data.frame(model()$coefficients)
})
output$res <- renderTable({
as.data.frame(model()$residuals)
})
output$num <- renderText({
req(input$obs)
})
input_value <- reactive({
input$obs
})
predic <- reactive({
predict(model, newdata = data.frame(input_value))
})
output$p <- renderText({
predic()
})
# output$plot <- renderPlot({
# ggplot(mtcars, aes(mtcars[,c(input$variable)], mtcars[, c(input$variable2)]))
# })
# output$data3 <- renderTable({
# brushedPoints(mtcars, input$plot_brush, xvar = input$variable, yvar = input$variable2)
# })
}