Shiny App disconnecting when using `stopApp` in `onSessionEnded`

I was wondering, why a shiny app deployed with Shiny server disconnected often. Took me a long time to figure out, but now I think it has sth. to do with this line of code, which I had in my server function:

session$onSessionEnded(function() {stopApp()})

When I have the app open in two browsers and then close one browser, after about 15 seconds the app will disconnect in the other browser. Removing this line seems to fix it. Maybe someone can add some explanation?

Stops the currently running Shiny app, returning control to the caller of ‘runApp’.

What the code snippet is telling R to do is: "When a user stops their session, kill the whole Shiny app". (Which would stop all other user sessions.) A single app can support many user sessions simultaneously.

This is equivalent to hitting ctrl + c or Esc in RStudio.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.