Hello all,
I'm often here helping others but the tables have turned and I would benefit from help from the community.
I would like to understand a best practice way to log a shiny app, so as to track the console, which will also include shiny error traces from shiny::devmode.
Here is a reprex, I have two issues regarding it, but first the code:
library(shiny)
shiny::devmode()
ui <- fluidPage(
actionButton("simple", "Just to add something normal to the log"),
actionButton("force_error_button", "Force an Error")
)
close_sink_and_quit <- function(){
sink(file = NULL,type = "message")
sink(file = NULL,type = "output")
close(con = flog)
stopApp()
}
options(error = close_sink_and_quit)
options(shiny.error = close_sink_and_quit)
flog <- file("my_shiny_log", open = "wt")
sink(file = flog, split = TRUE)
sink(file = flog, type = "message")
server <- function(input, output, session) {
onStop(function() {cat("Session stopped\n") ;close_sink_and_quit()})
observeEvent(input$simple,
cat("\npressed for",input$simple))
observeEvent(input$force_error_button, {
stop(paste("Error Forced at ", Sys.time()))
})
}
shinyApp(ui, server)
if I refrain from pressing my force error button, but hit the simple button a few times,
I happily get the corresponding message in my console, and in "my_shiny_log" file .
if I force an error, although I see a useful stack trace in the console, this is not represented in the "my_shiny_log" file.
i.e.
Warning: Error in <observer:observeEvent(input$force_error_button)>: Error Forced at 2022-07-26 12:43:12
76: h
75: .handleSimpleError
74: stop
73: <observer:observeEvent(input$force_error_button)> [#11]
72: valueFunc
71: ..stacktraceon..
70: contextFunc
Can anyone advise me of my options here ?
how to get the warning stacktrace to be sinked ? (or some alternative to sink
which will have the required effect ?)