【问题标题】:Warnings/Errors in shiny.R renderUI checkboxGroupInput dynamic generationshiny.R renderUI checkboxGroupInput 动态生成中的警告/错误
【发布时间】:2013-11-21 22:23:37
【问题描述】:

我在server.R 中运行以下代码。 “COL_OP1”和“COL_OP2”是数据框“df”中的两列(还有其他列)。我想使用uiOutput('op1') 在ui.R 中生成动态复选框,它工作正常,但显示警告和错误。

op1 的选择很少,op2 应该基于此生成复选框。

警告是

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

错误是

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

这是我的代码:

  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)
  })

【问题讨论】:

  • 您能否让您的示例可重现? df 是什么? supv 是什么?
  • 看起来df$COL_OP中什么都没有
  • df() 是一个recative输出,它是一个数据框
  • 嗨 Stephane Laurent,我想从 COL_OP 列的唯一值填充 CheckBoxes

标签: r dynamic checkbox shiny


【解决方案1】:

以下代码删除了我的错误,我取消了警告

  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)
  })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-16
    • 1970-01-01
    • 2019-01-06
    • 2013-08-16
    • 1970-01-01
    • 2017-11-08
    • 1970-01-01
    • 2018-11-26
    相关资源
    最近更新 更多