Closed Claudius-Appel closed 4 months ago
note: each control's cb must implement its own trycatch-environment, wrapping the entire server-logic into a single tryCatch()
-statement will not work.
consider the viability of
## End(Don't show)
library(shiny)
ui <- fixedPage(
markdown(c(
"Set the number to 8 or higher to cause an error",
"in the `renderText()` output."
)),
sliderInput("number", "Number", 0, 10, 4),
textOutput("text"),
hr(),
markdown(c(
"Click the button below to crash the app with an unhandled error",
"in an `observe()` block."
)),
actionButton("crash", "Crash the app!")
)
log_event <- function(level, ...) {
ts <- strftime(Sys.time(), " [%F %T] ")
message(level, ts, ...)
}
server <- function(input, output, session) {
log_event("INFO", "Session started")
onUnhandledError(function(err) {
# log the unhandled error
level <- if (inherits(err, "shiny.error.fatal")) "FATAL" else "ERROR"
log_event(level, conditionMessage(err))
})
onStop(function() {
log_event("INFO", "Session ended")
})
observeEvent(input$crash, stop("Oops, an unhandled error happened!"))
output$text <- renderText({
if (input$number > 7) {
stop("that's too high!")
}
sprintf("You picked number %d.", input$number)
})
}
shinyApp(ui, server)
preliminary tests seem to suggest that these registrations accumulate for unknown reasons UNLESS the session is manually restarted after each error.
i.e., within one session restarting the app 5 times and inducing an error manually will invoke 1 1 + 2 1 + 2 + 3 1 + 2 + 3 + 4 1 + 2 + 3 + 4 + 5
= 35 loggings in total.
How to fix this?
<html>
<body>
<!--StartFragment-->
> devtools:::document() ℹ Updating duflor.gui documentation ℹ Loading duflor.gui > duflor_gui() Lade nötiges Paket: shiny Attache Paket: ‘shiny’ Die folgenden Objekte sind maskiert von ‘package:duflor.gui’: dataTableOutput, renderDataTable Listening on http://127.0.0.1:3663 INFO [2024-05-04 19:38:27] Session started [1] "pre-error" Warnung: Error in : THIS IS A SIMPLE ERROR 3: runApp 2: print.shiny.appobj 1: <Anonymous> FATAL [2024-05-04 19:38:34] THIS IS A SIMPLE ERROR > duflor_gui() Listening on http://127.0.0.1:3663 INFO [2024-05-04 19:38:46] Session started [1] "pre-error" Warnung: Error in : THIS IS A SIMPLE ERROR 3: runApp 2: print.shiny.appobj 1: <Anonymous> FATAL [2024-05-04 19:38:52] THIS IS A SIMPLE ERROR FATAL [2024-05-04 19:38:52] THIS IS A SIMPLE ERROR > > devtools:::document() ℹ Updating duflor.gui documentation ℹ Loading duflor.gui > duflor_gui() Listening on http://127.0.0.1:3663 INFO [2024-05-04 19:41:36] Session started [1] "pre-error" Warnung: Error in : THIS IS A SIMPLE ERROR 3: runApp 2: print.shiny.appobj 1: <Anonymous> FATAL [2024-05-04 19:41:45] THIS IS A SIMPLE ERROR FATAL [2024-05-04 19:41:45] THIS IS A SIMPLE ERROR FATAL [2024-05-04 19:41:45] THIS IS A SIMPLE ERROR Fehler in oUE() : Argument "oUE" fehlt (ohne Standardwert) Called from: callback(...) Browse[1]> > > > > devtools:::document() ℹ Updating duflor.gui documentation ℹ Loading duflor.gui
--
> | >
>
<!--EndFragment-->
</body>
</html>
TODO: For the try catch block, check if changes to members of DATA
made within thetry
-block propagate to thecatch error
-routine.
TODO: Loading/saving states must issue a shinyNotification()
upon succession.