Claudius-Appel / duflor.gui

GUI frontent for `duflor`-package
https://claudius-appel.github.io/duflor.gui/
MIT License
0 stars 0 forks source link

implement manual and error-catching bookmarking for the main analysis callback #51

Closed Claudius-Appel closed 4 months ago

Claudius-Appel commented 4 months ago
  1. Manual bookmarking: Manually triggered, saves to a selected file, and lets user restore from there
  2. trycatch-bookmarking: triggered when server-logic runs into an error. must save to a temporary directory, then in the error-message return the location. This is intended for sudden bug-reports and keeping sane states, however it will have to be wiped when the computer shuts down.
Claudius-Appel commented 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.

Claudius-Appel commented 4 months ago

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)
Claudius-Appel commented 4 months ago

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>
Claudius-Appel commented 4 months ago

TODO: For the try catch block, check if changes to members of DATA made within thetry-block propagate to thecatch error-routine.

Claudius-Appel commented 4 months ago

TODO: Loading/saving states must issue a shinyNotification() upon succession.