You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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. If this is not currently possible, I would request this as a feature.
Here is a reprex to illustrate the issue:
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, as well as 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've been pulling my hair out on this point :D
example of trace that shows in console but not in the sink log file :
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
so to summarise, is it possible to duplicate the full console including devmode's stacktrace in a sinked logging file?, or would this require a new devmode feature/bugfix to achieve ?
I had it suggested to me that a combination of wrapping the app inside a callr/processx might be a way to go, though this seemed rather heavyweight to me... thoughts ?
The text was updated successfully, but these errors were encountered:
nir4most
changed the title
shiny::devmode and logging the R console to a log file via sink() - traces absent
How to log shiny::devmode() output ?
Oct 6, 2022
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. If this is not currently possible, I would request this as a feature.
Here is a reprex to illustrate the issue:
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, as well as 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've been pulling my hair out on this point :D
example of trace that shows in console but not in the sink log file :
so to summarise, is it possible to duplicate the full console including devmode's stacktrace in a
sink
ed logging file?, or would this require a new devmode feature/bugfix to achieve ?I had it suggested to me that a combination of wrapping the app inside a callr/processx might be a way to go, though this seemed rather heavyweight to me... thoughts ?
The text was updated successfully, but these errors were encountered: