Hello,
I'm trying to predict a value in shiny app after regression. During the training in regression, I converted a few columns from boolean to numeric or character to numeric (by categorizing). Now in shiny app, it says that those column inputs (that require conversion to numeric) are different from the fit.
I looked up the error and it was suggested to use "updateRadioButtons" to update the values of those columns to numeric. But it is giving me errors. Not sure what's wrong with my code.
server <- function(input, output,session) {
output$charges= renderText({
observeEvent({
a <- as.numeric(ifelse(input$sex == 'male', 1, 0))
updateRadioButtons(session,"sex",value=a)
b <- as.numeric(ifelse(input$smoker == 'yes', 1, 0))
updateRadioButtons(session,"smoker",value=b)
c <- as.numeric(ifelse(input$region == 'southwest', 0,
ifelse(input$region == 'southeast', 1,
ifelse(input$region == 'northwest', 2, 3))))
updateRadioButtons(session,"region",value=c)
})
#input$sex <- ifelse(input$sex == 'male', 1, 0)
#input$smoker <- ifelse(input$smoker == 'yes', 1, 0)
#input$region <- ifelse(input$region == 'southwest', 0,
# ifelse(input$region == 'southeast', 1,
# ifelse(input$region == 'northwest', 2, 3)))
# Create a data frame with user inputs
input_data <- data.frame(age = input$age,
sex = input$sex,
bmi = input$bmi,
children = input$children,
smoker = input$smoker,
region = input$region)
prediction <- predict(first_model, newdata = input_data)
paste("Your estimated medical insurance for the upcoming year would be $", prediction)
})
}