rshinyrestart

Why does R sometimes crash and shut down when a Shiny App fails to terminate by x-ing out of the window?


I usually close a Shiny App by x-ing out of the App's window as shown in the 1st image below. Depending on the App, sometimes this doesn't stop the App so I then go to the R studio console and click on "Stop" as shown in the 2nd image below. Sometimes this doesn't stop the App either, and R shuts down and restarts after a warning window pops up asking me if I want to restart R: clicking "No" doesn't stop the runaway App, so the only way I know how to stop the App is to click "Yes" and restart.

Why is this happening and how do I fix this?

As far as I can tell the Apps where this happens are bug-free, in the sense they work fine for me and I got no other errors messages or warnings.

1st image, how I normally stop an App:

enter image description here

2nd image, where I go on R Studio console to stop a runaway App:

enter image description here


Solution

  • I suggest the solution posted on Posit Community: R crashes shiny app

    library(shiny)
    ui <- fluidPage()
    server <- function(input, output, session) {  
    session$onSessionEnded(function() { stopApp() })}
    shinyApp(ui, server)