IF else语句不返回R闪亮的数据帧

时间:2018-04-01 15:44:06

标签: r dataframe shiny

我有以下数据框

          DF<-data.frame("variable"<-c("Q1", "Q2", "Q3", "Q4"),
           "estimatesum"<-c(10,3,1,2))
           names(DF)<-c("variable", "estimatesum")

      DF2<-  data.frame("Variable"<-c("New", "Phone", "get", "Buy", "Sim", 
     "Card"), "estimatesum"<-c(1:6))

客户总数为10000

   TotalBase<-10000

我在R中为thr UI和服务器编写了以下代码。

   ui<- fluidPage(
   textInput("message", label = "message",placeholder = 
   "'"),actionButton("do", "Click Me"),textInput("size", label = "size", 
   placeholder = ':'),dateInput("Date",label = "Date"),
   mainPanel(plotOutput("Plot1"),verbatimTextOutput("Output1")))






  server <- function(input, output) {output$Plot1 <- renderPlot({
   set.seed(1234)
   wordcloud(words = DF2$variable, freq = DF2$estimatesum, min.freq = 1,
   max.words=200, random.order=FALSE, rot.per=0.35, colors=brewer.pal(8, 
   "Dark2"))})
    text2 <- reactive({{csize<-input$size
    csize<-as.numeric(csize)
    if(csize<=quantile(TotalBase,0.25)) 
    {Out2=DF[DF$variable=="Q1",]}
    else if((csize>quantile(TotalBase,0.25)) & 
    (csize<=quantile(TotalBase,0.5)))
    {Out2==DF[DF$variable=="Q2",]}
    else if((csize>quantile(TotalBase,0.5)) & 
    (csize<=quantile(TotalBase,0.75)))
    {Out2=DF[DF$variable=="Q3",]}
    else{(Out2=DF[DF$variable=="Q4",])}

    outputtable<-Out2})} 
   output$Output1 <- renderPrint({sum(text2()$estimatesum)})}

     shinyApp(ui, server)

我反复收到以下错误。

    Listening on http://127.0.0.1:4495
    Warning: Error in if: missing value where TRUE/FALSE needed
    Stack trace (innermost first):
    100: <reactive:text2> [#10]
    89: text2
    88: renderPrint [#24]
    87: func
    86: eval
    85: eval
    84: withVisible
    83: evalVis
    82: utils::capture.output
    81: paste
    80: origRenderFunc
    79: output$Output1
    4: <Anonymous>
     3: do.call
    2: print.shiny.appobj
    1: <Promise>

我无法找到错误。我在函数外面运行了循环。它取得了成果。我请求有人帮助我。我根本无法理解错误

0 个答案:

没有答案