Choose specific column in R Shiny based on selectInput

652 views Asked by At

I have a problem with choose specific column depends on selectInput. I try to make confusion metrix. I have argument (data = result) but now i need reference = ? , which is one specific column of data_t_add. That column (which have to be reference) have to be input$choose_y of data_t_add. How can I do it ? Thank you.

Server:

   output$choose_y <- renderUI({
     
     y_choices <- names(data())
     selectInput('choose_y', label = 'Choose Target Variable', choices = y_choices)
   })
   
   output$choose_x <- renderUI({
     x_choices <- names(data())[!names(data()) %in% input$choose_y]
     checkboxGroupInput('choose_x', label = 'Choose Predictors', choices = x_choices)
   })
   
   
   
   observeEvent(input$c50, {
     form <- paste(isolate(input$choose_y), '~', paste(isolate(input$choose_x), collapse = '+'))
     c50_fit <- eval(parse(text = sprintf("ctree(%s, data = data())", form)))
     output$tree_summary <- renderPrint(summary(c50_fit))
     output$tree_plot_c50 <- renderPlot({
       plot(c50_fit)
     })
     
     result <-  predict(c50_fit, newdata = data_t())
     data_t_add = cbind(data_t(), result)
     output$data_t_add_out <- renderTable({
         return(head(data_t_add))
     })
     
     tbl = confusionMatrix(result, REFERENCE, mode = "prec_recall")
     output$conf_matrix <- renderPrint({ tbl })
     
   })

##################### EDIT of SERVER 

try = data_t_add %>% select(input$choose_y)

     output$tripple <- renderPrint({
       return(str(try))
     })

     output$tripples <- renderPrint({
       return(str(data_t_add))
     })

     tbl = confusionMatrix(result, try, mode = "prec_recall")
     output$conf_matrix <- renderPrint({ tbl })
1

There are 1 answers

4
Pabort On

Without having a reproducible example, I would dare to say that using select() from dplyr can let you select the entire column of your choice

data() %>% 
  select(input$choose_y)