Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 更新shiny中相同单选按钮的choices参数_R_Shiny - Fatal编程技术网

R 更新shiny中相同单选按钮的choices参数

R 更新shiny中相同单选按钮的choices参数,r,shiny,R,Shiny,我想从R/Shining中的radioButtons小部件更新choices参数。当用户选择某个选项时,应根据用户的第一个选项更新choices参数。我用示例函数模拟了4个随机字母。更新似乎没有停止,并且更新了几次。如何防止多次更新的行为 下面是重现我的方法的代码: library("shiny") ui <- fluidPage( radioButtons("answerchoice", label = "item",

我想从R/Shining中的radioButtons小部件更新choices参数。当用户选择某个选项时,应根据用户的第一个选项更新choices参数。我用示例函数模拟了4个随机字母。更新似乎没有停止,并且更新了几次。如何防止多次更新的行为

下面是重现我的方法的代码:

library("shiny")

ui <- fluidPage(
    radioButtons("answerchoice", label = "item", choices = sample(letters, 4), selected = NULL,
                 )
    
)

server <- function(input, output, session) {
    observeEvent(input$answerchoice,{
        updateRadioButtons(
            session = session,
            inputId = "answerchoice",
            choices = sample(letters, 4)
        )
    })
}

shinyApp(ui = ui, server = server)
库(“闪亮”)

ui似乎问题出在
selected=NULL的默认设置上<代码>单选按钮
正在初始拾取一个值。这可能会导致多次更新。通过将所选
设置为“无”。应用程序没有无法控制地更新

library("shiny")

ui <- fluidPage(
  radioButtons("answerchoice",
               label = "item", 
               choices = sample(letters, 4),
               selected =  character(0)
  )
  
)

server <- function(input, output, session) {
  observeEvent(input$answerchoice,{
    updateRadioButtons(
      session = session,
      inputId = "answerchoice",
      choices = sample(letters, 4),
      selected =  character(0)
    )
  })
}

shinyApp(ui = ui, server = server)
库(“闪亮”)
用户界面