Nice one Stéphane.
I'm taking this opportunity to learn too. I think I have discovered good reasons to rely on observe() and isolate() rather than reactive(), though I suppose that mileage will vary depending on the purpose of the app.
I took Stéphane's code and added a few bells and whistles to keep track of what was going on. Namely, I added a numericInput box in which the user can add the delay to be passed to Sys.sleep (totally weird, but it's a demo for learning), and then I attempted to keep track of the total delay when different values of the argument of Sys.sleep were used.
I couldn't get it to work with a simple reactive() like the one you are using. One problem was that Sys.sleep was triggered as soon as the number in the numericInput box was changed and not just when the actionButton was actioned. Another problem was that without isolate-ing various bits of the code, the numbers were all wrong.
I haven't tested extensively, but I think the code below does the calculations right most of the time. If it doesn't, please fix it and get back to me ;-)
I have commented out the code based on a reactive, you can experiment to see what happens to the simple math of keeping track of the delay if you uncomment it.
I use an observe() like so. It is instructive to see what happens if you remove each of the isolate() and if you remove both, and if you remove the if(is.null(..)){return()}: the math is wrong, each time for different reasons.
observe({
input$trigger
if(is.null(input$trigger) || input$trigger == 0){return()} # needed for math below
delayValues$total <- isolate(delayValues$total) + isolate(input$delay)
})
Likewise if you don't wrap your Sys.sleep into an isolate, it will trigger even if the actionButton is not actioned (in this case the math is not updated).
But for your purpose the reactive() approach may well be satisfactory.
library("shiny")