【问题标题】:Choose specific column in R Shiny based on selectInput根据 selectInput 在 R Shiny 中选择特定列
【发布时间】:2022-01-04 19:47:18
【问题描述】:

我在选择特定列时遇到问题,具体取决于 selectInput。我试图使混淆矩阵。我有论点(数据=结果)但现在我需要参考=? ,这是 data_t_add 的一个特定列。该列(必须是参考)必须是 data_t_add 的 input$choose_y。我该怎么做 ?谢谢。

服务器:

   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 })

【问题讨论】:

    标签: r shiny shinydashboard shiny-server shiny-reactivity


    【解决方案1】:

    如果没有可重现的示例,我敢说使用 dplyr 中的 select() 可以让您选择您选择的整个列

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

    【讨论】:

    • 谢谢,但和我的实验一样的错误:datareference 中的错误应该是具有相同水平的因素。
    • 你能添加一个最小的例子吗?你能检查一下错误是在过滤还是在生成图上?
    • 现在我尝试打印数据的 str() - 有 3 个级别的因子,我打印了你的答案的 str() - 有 3 个级别的因子,但是当我尝试混淆矩阵时( ) 我收到关于...具有相同水平的因素的错误。
    • 我在我的问题中添加了 EDIT,因子在两个(结果和尝试)中都有 3 个级别,但在 cofusion 矩阵中有错误 - 错误:数据和参考应该是具有相同级别的因子。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    • 2021-11-26
    • 1970-01-01
    • 2021-07-09
    • 2019-12-10
    • 2015-05-28
    • 2021-05-17
    相关资源
    最近更新 更多