假设我有一个闪亮的应用程序,其功能可能需要很长时间才能运行.是否有可能有一个"停止"按钮告诉R停止长时间运行的呼叫,而不必停止应用程序?
我的意思是:
analyze <- function() {
lapply(1:5, function(x) { cat(x); Sys.sleep(1) })
}
runApp(shinyApp(
ui = fluidPage(
actionButton("analyze", "Analyze", class = "btn-primary"),
actionButton("stop", "Stop")
),
server = function(input, output, session) {
observeEvent(input$analyze, {
analyze()
})
observeEvent(input$stop, {
# stop the slow analyze() function
})
}
))
Run Code Online (Sandbox Code Playgroud)
编辑:发光讨论的x-post