shiny icon indicating copy to clipboard operation
shiny copied to clipboard

Fix for close ShinySession on on.exit

Open galachad opened this issue 5 years ago • 4 comments

The onSessionEnd is probably triggered by later loop and is never trigger on SIGINT signal. There is a difference between interactive and not interactive R process. In not interactive R process after global onStop callback, the R process is terminated immediately.

The minimal example:

library(shiny)

ui <- fluidPage(

)

server <- function(input, output, session) {
  onSessionEnded(function() {
    print("close ShinySession session")
  })
}

onStop(function() {
  # Custom code that was used before this PR.
  lapply(shiny:::appsByToken$keys(), function(session) {
    session <- shiny:::appsByToken$get(session)
    if (isFALSE(session$closed)) session$wsClosed()
  })
})

shinyApp(ui, server)

The gif example shows the difference. Peek 2020-01-09 10-11

If I can do some more in this case or you need more clarification, please let me know.

galachad avatar Jan 29 '20 22:01 galachad

I think that #2743 may have the same root cause as the issue you're describing.

In your command-line script, if, instead of using this PR, you add this after the call to runApp(), does the onSessionEnded callback execute properly?

for (i in 1:10) later::run_now()

wch avatar Feb 14 '20 20:02 wch

@wch I totally agree, it's even better to trigger later loop on stop callback. It's not really solved #2743 issue because the second runApp is executed before later loop. In my opinion it will be good to add run_now at the beginning of runApp.

runApp(app)
later::run_now()
runApp(app)

galachad avatar Feb 24 '20 08:02 galachad

I was to fast, I check twice and it does not execute callback properly.

galachad avatar Feb 24 '20 08:02 galachad

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Mar 05 '20 15:03 CLAassistant