rpart() を使用してツリー プロットを構築する光沢のあるアプリを作成しようとしています。私は 12 個の予測子を使用しています。checkboxInput() 値を使用して各予測子の使用を指定したいと考えています。各checkboxInputの値がブール値であることは知っています。通常、rpart() は、TRUE または FALSE を予測子の 1 つに掛けて、その予測子の使用を指定すると機能します。次のエラーが発生し続けます。
model.frame.default(formula = results ~ (input$Pred1 * meanrecchrge) + のエラー: 変数の長さが異なります ('input$Pred1' で見つかりました)
ui.R
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))})
})
})