Shiny Capture Crash|Disconnect

Is there a way to capture when a shiny application crashes/disconnects (i.e.: closes WebSocket connection) along with its traceback ~ message.

library(shiny)

ui <- fluidPage(
  actionButton("crash", "Crash")
)

server <- function(input, output, session) {
  session$onEnded(function(){
    print(warnings()) # nothing
    print(traceback()) # NULL
    print(shiny:::.globals$deepStack) # NULL
  })
 
  observeEvent(input$crash, {
    print(error) # no error object: disconnects
  })
}

shinyApp(ui, server)

Nothing I tried worked (see above).
It seems {shiny} does a lot of manipulation of the stacktrace, perhaps that is the reason?

Thank you but

  1. See docs onSessionEnded and onEnded are analogous.
  2. onStop results in the same.
  3. The question is how do I know the app crashed not how do I know it stopped.

Maybe this related discussion helps.

in relation to the related thread; I did raise an issue on the shiny/github enquiring as to best practice and how to work in this space; but seem to have no traction; perhaps if others with similar concerns add to my issue this would raise its profile.

How to log shiny::devmode() output ? · Issue #3677 · rstudio/shiny (github.com)

After setting options(shiny.fullstacktrace = TRUE) the traceback() call no longer results in NULL:

library(shiny)

options(shiny.fullstacktrace = TRUE)

ui <- fluidPage(
  actionButton("crash", "Crash")
)

server <- function(input, output, session) {
  session$onEnded(function(){
    cat("\nSTART traceback ---------------------------------------------------------\n")
    print(traceback())
    cat("\nEND traceback -----------------------------------------------------------\n")
  })
  
  observeEvent(input$crash, {
    print(error) # no error object: disconnects
  })
}

shinyApp(ui, server)

I don't know what version of shiny you are on but this is not working for me.

START traceback ---------------------------------------------------------
No traceback available 
NULL

END traceback -----------------------------------------------------------

In fact, to the best of my understanding, this is the default already it seems, see code.

The traceback is pushed to .globals$deepStack (see my question).
By the time onEnded or onStop runs this has been cleared, hence the issues.

Also posted on SO

You are right - it is populated only on the second run (shiny 1.7.3 - latest CRAN).

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.