代码之家  ›  专栏  ›  技术社区  ›  Vikram Karthic

条件面板和单选按钮选择不起作用

  •  0
  • Vikram Karthic  · 技术社区  · 6 年前

    我试图使用基于单选按钮输入的条件面板,如下所示

    radioButtons("Type","Review Type:",c("Type1","Type2","Type3"),inline=T)
    

    有条件的小组声明如下:,

    conditionalPanel(condition = "input.Type == 'Type1'",wellPanel(
    radioButtons("Question1", "do you know R shiny?"choices = c("Y","N","NA"),selected = "Y",inline=T)
    
    conditionalPanel(condition = "input.Type == 'Type2'",wellPanel(
    radioButtons("Question1", "do you know Python?"choices = c("Y","N","NA"),selected = "Y",inline=T)
    
    
    conditionalPanel(condition = "input.Type == 'Type3'",wellPanel(
    radioButtons("Question1", "do you know Java?"choices = c("Y","N","NA"),selected = "Y",inline=T)
    

    如果您注意到条件面板中的单选按钮id(“问题1”)在所有条件面板中都是相同的,那么条件本身对我有效,但我已经设置了 selected = "Y" 对于因某种原因不能按预期工作的所有单选按钮(仅在第三个条件面板上工作)

    1 回复  |  直到 6 年前
        1
  •  0
  •   kluu    6 年前

    这是因为你所有的 radioButtons id ,因此它们仅被视为一个UI元素。给你的

    ui <- fluidPage(
      radioButtons(inputId = "Type", 
                   label = "Review Type:",
                   choices = c("Type1", "Type2", "Type3"),
                   inline = T),
      conditionalPanel(condition = "input.Type == 'Type1'",
                       wellPanel(
                         radioButtons(inputId = "Question1", 
                                      label = "do you know R shiny?", 
                                      choices = c("Y", "N", "NA"),
                                      selected = "Y",
                                      inline = T)
                       )
      ),  
      conditionalPanel(condition = "input.Type == 'Type2'",
                       wellPanel(
                         radioButtons(inputId = "Question1", 
                                      label = "do you know Python?", 
                                      choices = c("Y", "N", "NA"),
                                      selected = "Y",
                                      inline = T)
                       ) 
      ),
      conditionalPanel(condition = "input.Type == 'Type3'",
                       wellPanel(
                         radioButtons(inputId = "Question1", 
                                      label = "do you know Java?", 
                                      choices = c("Y", "N", "NA"),
                                      selected = "Y",
                                      inline = T)
                       )
      )
    )