1
我有类似闪亮可变覆盖
step <- 0
observeEvent(input$myInput, {
print(step)
if(!is.null(input$myInput) && step == 0 {
# do something
step <- 1
print(step)
} else if(!is.null(input$myInput) && step == 1) {
# do something
print("Been in second condition")
} else {
# do something else
}
})
当我执行我的应用程序,并在第一次observeEvent
踢,step
如预期0
和第一if-condition
开始。最后它设置step <- 1
。那里的print()
显示我step
是1
。但是,当第二次踢observeEvent
时,step
仍然是0
。这就是print
声明显示的内容。这是为什么?
@ john-paul的答案是正确的。要修复它,或者使用'<< - '或者'reactiveValues()'对你的用例有意义 –