I am creating an Rshiny app to run a an xgboost survival model. To do this, the categorical variables in the UI need to be entered into the model as one hot encoded variables. I created a blank dataframe and then used reactive values to adjust the variables. I also have the model preloaded. However when I run the app, I get this error:
xgb.DMatrix does not support construction from closure
I am trying to figure out a work around but need some advice
This is the code I have setup now
ui <- fluidPage(
sidebarPanel(
sliderInput("dxage", "Dx Age:",
value = 65, min = 18, max = 90
),
selectInput("ethnism_t", "Race/Ethnicity:",
c("Non-Hispanic White"=1,
"Non-Hispanic Black"=2,
"Asian, Hawaiian, Pacific Islander"=3,
"Hispanic"=4,
"Other"=9)
), actionButton("calculate", "Calculate")
),
mainPanel(
plotOutput("survplot")
),
)
server <- function(input, output) {
observeEvent(input$calculate, {
df$dxage = input$dxage
df$ethnism_1 <- ifelse(input$ethnism_t %in% 1, 1, 0)
df$ethnism_2 <- ifelse(input$ethnism_t %in% 2, 1, 0)
df$ethnism_3 <- ifelse(input$ethnism_t %in% 3, 1, 0)
df$ethnism_4 <- ifelse(input$ethnism_t %in% 4, 1, 0)
df$ethnism_9 <- ifelse(input$ethnism_t %in% 9, 1, 0)
df$status = 0
df$time = 1
})
xgb_test_case <- reactive(as_sgb_data(df, time = time, status = status))
output$survplot<- renderPlot({
predict(fits, xgb_test_case)
})
} shinyApp(ui = ui, server = server)