1

我正在尝试创建一个使用 rpart() 构建树图的闪亮应用程序。我正在使用 12 个预测器,我想通过 checkboxInput() 值指定每个预测器的使用。我知道每个 checkboxInput 的值都是布尔值。通常,当我将 TRUE 或 FALSE 乘以我的一个预测变量以指定使用该预测变量时,rpart() 会起作用。我不断收到以下错误:

model.frame.default 中的错误(公式 = 结果〜(input$Pred1 * meanrecchrge)+:可变长度不同(为 'input$Pred1' 找到)

用户界面

library(shiny)
require(rpart)
require(rpart.plot)

shinyUI(fluidPage(
  titlePanel("Tree Diagram of Churn Data"),

sidebarLayout(    

 sidebarPanel(
      sliderInput("MinSplitVal",
                  "Minsplit Value",
                  min = 1,
                  max = 40000,
                  value = 1)),

 mainPanel(
   plotOutput("TreePlot"))),

wellPanel(      
        h3("Predictors"),
checkboxInput("Pred1", "Mean total recurring charge", TRUE),
checkboxInput("Pred2", "% change in minutes of use", TRUE),
checkboxInput("Pred3", "% change in revenues", FALSE),
checkboxInput("Pred4", "Months in service", FALSE),
checkboxInput("Pred5", "Number of unique substitutes",  FALSE),
checkboxInput("Pred6", "Number of active substitutes", FALSE),
checkboxInput("Pred7", "Days owning current equipment", FALSE),
checkboxInput("Pred8", "Age of first HH member", FALSE),
checkboxInput("Pred9", "Low credit rating -de", FALSE),
checkboxInput("Pred10", "Refurbished handset", FALSE),
checkboxInput("Pred11", "Web-capable handset", FALSE),
checkboxInput("Pred12", "Customer called retention team", FALSE)
)

))

服务器.R

library(shiny)
require(rpart)
require(rpart.plot)


shinyServer(function(input, output) {


output$TreePlot <- renderPlot({rpart.plot({rpart(outcome~
                  (input$Pred1*meanrecchrge)+(input$Pred2*percchangemin)
                 +(input$Pred3*percchangerev)+(input$Pred4*servmonths)
                 +(input$Pred5*numuniqsubs)+(input$Pred6*numactvsubs)
                 +(input$Pred7*daysowned)+(input$Pred8*agefirst)
                 +(input$Pred9*creditde)+(input$Pred10*refurb)
                 +(input$Pred11*webcap)+(input$Pred12*retcall), 
                 data = ChurntrainPreImpute, method = "class", 
                control = rpart.control(minsplit = 1))})
})
 })
4

0 回答 0