R闪亮:eventReactive / ObserveEvent,eventExpr具有AND

时间:2020-04-22 09:18:54

标签: r shiny

如何使eventReactive / ObserveEventeventExpr表达式取决于两个输入,例如actionButtonselectInput。我仅在第一个selectInput更改并且单击了操作按钮的情况下,才尝试更新第三个selectInput的值。但是,如果仅单击actionButton,则保留原始值;如果仅更改第一个selectInput,则不执行任何操作。

我尝试过:

observeEvent({input$selectInput1 & input$actionButton}, {
    updateSelectInput(session = session, inputId = "input2", label = "b", choices = input$selectInput1, selected = input$selectInput1)
})

但是我不能在&中使用eventExpr

2 个答案:

答案 0 :(得分:1)

我的回答来自以下线程:Shiny R observeEvent with Multiple Conditions from selectInput,我也想在这里显示它,因为它对我来说很好。

您的解决方案可能是

observeEvent(req(input$selectInput1, input$actionButton), {
    updateSelectInput(session = session, inputId = "input2", label = "b", choices = input$selectInput1, selected = input$selectInput1)
})

答案 1 :(得分:0)

您可以

observeEvent(list(input$selectInput1, input$actionButton), {
    updateSelectInput(session = session, inputId = "input2", label = "b", choices = input$selectInput1, selected = input$selectInput1)
})