简体   繁体   中英

Warnings/Errors in shiny.R renderUI checkboxGroupInput dynamic generation

I am running following code in server.R . "COL_OP1" and "COL_OP2" are two columns in a data frame "df" (there are other columns as well). I would like to generate dynamic checkboxes in ui.R using uiOutput('op1') , which is working fine, but showing warnings and errors.

op1 has few choices and based on this op2 should generate check boxes.

Warning is

"Warning in is.na(e2) :
  is.na() applied to non-(list or vector) of type 'NULL'"

Error is

"Error in mapply(ids, choices, names(choices), SIMPLIFY = FALSE, USE.NAMES = FALSE,  : 
  zero-length inputs cannot be mixed with those of non-zero length"

Here my code:

  output$op1 = renderUI({ 
    op1 = unique(df()$COL_OP1)
    op1 = op1[order(op1)]
    checkboxGroupInput('OP1', 'Choose OP1', op1, selected = op1) 
  })

  output$op2 <- renderUI({
    op2 = unique(df()[df()$COL_OP1==input$OP1,]$COL_OP2)
    op2 = op2[order(op2)]
    checkboxGroupInput('OP2', 'Choose OP2',op2, selected = op2)
  })

The following code removed my error and I suppressed the warnings

  output$op1 = renderUI({ 
    op1 = unique(df()$COL_OP1)
    op1 = op1[order(op1)]
    checkboxGroupInput('OP1', 'Choose OP1', op1, selected = op1) 
  })

  output$op2 <- renderUI({
    if(is.null(input$OP1))
       return(NULL)
    op2 = suppressWarnings(unique(df()[df()$COL_OP1==input$OP1,]$COL_OP2))
    op2 = op2[order(op2)]
    checkboxGroupInput('OP2', 'Choose OP2',op2, selected = op2)
  })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM