警告:if:参数的长度为零时出错

时间:2019-06-12 12:53:42

标签: r if-statement shinydashboard

在选择单选按钮之前,代码可以正常工作(按国家/地区/办公室/客户/等按不同的值过滤数据)。 我收到此错误:

Warning:Error screenshot

,下面是提到的包含此错误的代码行:

  output$levelQueryUi <- renderUI({
    radioButtons("analysisLevel", label = "Level of Analysis",
                 choices = list("Office Country" = 1, "Office" = 2, "Market" = 3, "Source Market"  = 4, "Customer" =5), 
                 selected = 1)
  })
    officedata <- reactive({

       #office country Radio Button id selescted
       if(input$analysisLevel == 1)
       {
       subset(
         ct,
       ct$`Office Country` %in%  input$officecountry
       )
       }
       # office Radio Button id selescted
       else if(input$analysisLevel == 2)
         {
           subset(
             ct,
             ct$Office %in%  input$office
           )
         }
         else if(input$analysisLevel == 3)
           {
         subset(
           ct,
           ct$Market %in%  input$market
         )
         }
       else if(input$analysisLevel == 4)
       {
         subset(
           ct,
           ct$`Source Market` %in%  input$sourcemarket
         )
       }
       else if(input$analysisLevel == 5)
       {
         subset(
           ct,
           ct$Customer %in%  input$customer
         )
       }
       else{
         return(ct)
       }
     })

     #filtered data
     filteredcancelled <- reactive({
       subset(
         officedata(),
         officedata()$Status %in% "Cancelled"
       )
     })

     #Average Project Size
     officedataconcom <- reactive({ 
       subset(
         officedata(),
         officedata()$Start >= "2018-01-01" &
           officedata()$Status == "Completed" |
           officedata()$Status == "Confirmed"
       )
     })

     ##############################DATA BY OFFICE OFFICE COUNTRY MARKET SOURCE MARKET AND CUSTOMER###########################
     output$numofenqby <- renderValueBox({
       valueBox(nrow(officedata()), "Number of Enquiries", color = "blue", icon = icon("star"))

     })

我查看了他们以尝试找出错误所在,但我没有,并且我也尝试在发布此问题之前先查看堆栈中的类似问题溢出,但没有任何结果。< / p>

非常重要的一点是,即使出现此警告,我的代码仍然可以正常工作。这只是一个警告,但我希望摆脱它。

这是输出,当我单击其他选项时,它给了我上述错误: Filtering data 因此,我的控制台保持清洁,直到我尝试在这些不同的按钮(Office Country / Office / Market / Source Market / Customer)之间移动时,当我这样做时,我会得到那些警告。

与单选按钮相关的UI代码

  tabItem(tabName = "explorer",
                                    fluidPage(
                                      title = "Market Explorer",
                                      column(width = 3,
                                             box(
                                               title = "Query Builder",
                                               status = "primary",
                                               width = 12,
                                               solidHeader = TRUE,
                                               background = "navy",
                                               box(
                                                 width = 12,
                                                 status = "primary",
                                                 solidHeader = FALSE,
                                                 background = "navy",
                                                 uiOutput("levelQueryUi")
                                               ),# end of box
                                               conditionalPanel(
                                                 condition = "input.analysisLevel == 1",
                                                 box(
                                                   status = "primary",
                                                   solidHeader = FALSE,
                                                   width = 12,
                                                   background = "navy",
                                                   uiOutput("officecountryUi")
                                                 )# end of box
                                               ),# end of conditional panel 
                                               conditionalPanel(
                                                 condition = "input.analysisLevel == 2",
                                                 box(
                                                   status = "primary",
                                                   solidHeader = FALSE,
                                                   width = 12,
                                                   background = "navy",
                                                   uiOutput("officeUi")
                                                 )# end of box
                                               ),# end of conditional panel  
                                               conditionalPanel(
                                                 condition = "input.analysisLevel == 3",
                                                 box(
                                                   status = "primary",
                                                   solidHeader = FALSE,
                                                   width = 12,
                                                   background = "navy",
                                                   uiOutput("marketUi")
                                                 )# end of box
                                               ),# end of conditionalpanel    
                                               conditionalPanel(
                                                 condition = "input.analysisLevel == 4",
                                                 box(
                                                   status = "primary",
                                                   solidHeader = FALSE,
                                                   width = 12,
                                                   background = "navy",
                                                   uiOutput("sourcemarketUi")
                                                )#end of box
                                               ),# end of conditionalpanel
                                               conditionalPanel(
                                                 condition = "input.analysisLevel == 5",
                                                 box(
                                                   status = "primary",
                                                   solidHeader = FALSE,
                                                   width = 12,
                                                   background = "navy",
                                                   uiOutput("customerUi")
                                                 )#end of box
                                               ),# end of conditionalpanel
                                                box(
                                                 status = "primary",
                                                 solidHeader = FALSE,
                                                 width = 12,
                                                 background = "navy",
                                                 sliderInput("hviQuery", label = "Project Value Range ($000)", min = 0, max = 2000, value = c(0,1000)),
                                                 checkboxInput("maxValue", label = "Include all values exceeding $2m", value = FALSE)
                                               ), # end of box
                                               box(
                                                 status = "primary",
                                                 solidHeader = FALSE,
                                                 width = 12,
                                                 background = "navy",
                                                 selectInput("horizon", label = "Time Horizon:", 
                                                             choices = c("Monthly", "Quarterly", "Annual", "5 Year", "10 Year"),
                                                             selected = "Annual",
                                                             selectize = FALSE)
                                               ),# end of box
                                               actionButton("query", label = "Go") 
                                             )# end of box
                                      ),# end of column
                                      # conditionalPanel(
                                      #   condition = "input.query",
                                        column(width = 9,
                                               box(
                                                 title = "Market Data",
                                                 status = "primary",
                                                 width = 12,
                                                 solidHeader = TRUE,
                                                 collapsible = TRUE,
                                                 fluidRow(
                                                   valueBoxOutput("numofenqby", width = 4),
                                                   valueBoxOutput("averageprojectsize", width = 4),
                                                   valueBoxOutput("Materialisationrate", width = 4),
                                                   valueBoxOutput("cancelledworkvalueby", width = 4),
                                                   valueBoxOutput("averageGOPby", width = 4),
                                                   valueBoxOutput("confirmedasperby", width = 4),
                                                   valueBoxOutput("pastrequestsby", width = 4),
                                                   valueBoxOutput("ofcorporateby", width = 4),
                                                   valueBoxOutput("ofagencyby", width = 4))))))

请帮忙吗?我真的会很感激

0 个答案:

没有答案