【发布时间】:2018-12-14 12:22:36
【问题描述】:
我正在努力让 observeEvent 进程在触发事件后只运行一次 - 单击按钮。这说明:
require(shiny)
ui = fluidPage(
textInput("input_value", '1. input a value. 2. click button. 3. input another value', ''),
actionButton("execute", 'execute'),
textOutput('report')
)
server = function(input, output, session) {
observeEvent(input$execute, {
output$report = renderText(input$input_value)
})
}
shinyApp(ui = ui, server = server, options = list(launch.browser = T))
您会看到,在单击按钮一次后,textOutput 会响应 textInput 更改而不是按钮单击。
我试过这种方法:
server = function(input, output, session) {
o = observeEvent(input$execute, {
output$report = renderText(input$input_value)
o$destroy
})
}
没有效果。我也尝试过使用isolate 函数,但没有成功。感谢您的建议。
【问题讨论】:
-
这是一个非常有趣的问题。我(闪亮的新手)认为你的代码应该像发布的那样工作。我在这里问了一个后续问题:community.rstudio.com/t/…