jeudi 3 juin 2021

R shiny if returning error even though value returns true or false

So I have an if statement set to check if a checkbox is selected or not, with the checkbox returning either TRUE or FALSE, however I am getting an error and I cannot figure out why. I have provided extracts of the code that is involved. The weird thing is, when the checkbox is not selected everything runs fine, but as soon as the checkbox returns TRUE, the error appears.

Error: Warning: Error in if: missing value where TRUE/FALSE needed.

UI

    wellPanel(
      
      fluidRow(
        checkboxInput(inputId = "chckL1", "Line Drawer")
      ),
      
      fluidRow(
        column(6, numericInput(inputId = "num1_Y1", "Y1", value = NA)),
        column(6,numericInput(inputId = "num1_Y2", "Y2", value = NA))
      ),

      dateRangeInput(inputId = "dtrng1", "Date Range", start = Sys.Date(), end = Sys.Date(), max = Sys.Date())
    ),
    
    "Best Fit Line 2",
    
    wellPanel(
      
      fluidRow(
        column(6, numericInput(inputId = "num2_Y1", "Y1", value = NA)),
        column(6,numericInput(inputId = "num2_Y2", "Y2", value = NA))
      ),
      
      dateRangeInput(inputId = "dtrng2", "Date Range", start = Sys.Date(), end = Sys.Date(), max = Sys.Date())
    ),
    
    "Best Fit Line 3",
    
    wellPanel(
      
      fluidRow(
        column(6, numericInput(inputId = "num3_Y1", "Y1", value = NA)),
        column(6,numericInput(inputId = "num3_Y2", "Y2", value = NA))
      ),
      
      dateRangeInput(inputId = "dtrng3", "Date Range", start = Sys.Date(), end = Sys.Date(), max = Sys.Date())
    ),

    actionButton(inputId = "updtBtn", "Update")
  )
),

Server

CSLine = eventReactive(c(input$updtBtn, input$plot_dblclick$y), {
            
            
              
        custy_1 = c(input$num1_Y1,input$num1_Y2)
        custy_2 = c(input$num2_Y1,input$num2_Y2)
        custy_3 = c(input$num3_Y1,input$num3_Y2)
        custx_1 = as.Date(c(input$dtrng1[1],input$dtrng1[2]))
        custx_2 = as.Date(c(input$dtrng2[1],input$dtrng2[2]))
        custx_3 = as.Date(c(input$dtrng3[1],input$dtrng3[2]))
        
        if(input$chckL1){
          custy_1 = c(input$plot_click$y, input$plot_dblclick$y)
          custx_1 = as.Date(c(input$plot_click$x,input$plot_dblclick$x))
        }
        
        #cust = data.frame(custy_1,custx_1,custy_2,custx_2,custy_3,custx_3)
        #cust
        tst = data.frame(custy_1,custx_1)

})

Aucun commentaire:

Enregistrer un commentaire