abratra
abratra

Reputation: 1

Using reactive values in linear prediction

I'm working on a calculator that can predict post-college income for a machine learning class. I'm having some trouble getting the calculator to work. I get this error:

Error in output$predincome <- renderText(output()) : 
  object of type 'closure' is not subsettable

When I run the code and my ShinyApp crashes.

Here is my code:

data <- read_rds("x3.rds")
model <- read_rds("fixed.rds")
ui <- fluidPage(theme = shinytheme("united"),
    
    br(),
    
    navbarPage("Postgraduate Income Calculator",
        selectInput("tier", "College Attended:", levels(data$tier))),
        numericInput("par_mean", "Parent Income:", 0),
        numericInput("cohort", "Year Born:", 0),
        textOutput("predincome")

)

server <- function(input, output) {

df <- reactive(data.frame("cohort" = input$cohort, "tier" = input$tier, "par_mean" = input$par_mean))

  output <- reactive({predict(model, df())})
  output$predincome <- renderText(output())

}

Here is my model:

lm(k_mean ~ par_mean + factor(tier) + factor(cohort), data = training, weights = count)

Upvotes: 0

Views: 102

Answers (0)

Related Questions