Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to log shiny::devmode() output ? #3677

Open
nir4most opened this issue Aug 1, 2022 · 0 comments
Open

How to log shiny::devmode() output ? #3677

nir4most opened this issue Aug 1, 2022 · 0 comments

Comments

@nir4most
Copy link

nir4most commented Aug 1, 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:

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 ?

@nir4most 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant