9

Is there a way to include/print information into a shiny-server log file?

I am working with a shiny app which includes an user login and if my app crashes I would like to know what user caused this crash.

I tried to include this into my server.R:

#PRINT FOR LOG FILE------------
cat(paste0("Username: ",userdata$name, "\n"))
cat(paste0("Datum: ",Sys.time(), "\n"))

But it doesn't work. Any ideas?

maRtin
  • 6,336
  • 11
  • 43
  • 66

2 Answers2

12

Add file=stderr() parameter to your cat:

cat(file=stderr(), paste0("Username: ",userdata$name, "\n"))
cat(file=stderr(), paste0("Datum: ",Sys.time(), "\n"))

As noted in this article:

A note about stderr(): in most cases cat("my output") (i.e. printing to standard out) will work correctly, but in others (e.g. inside a renderPrint, which uses capture.output to redirect output), it won’t, so we recommend always sending trace output to stderr().

cakraww
  • 2,493
  • 28
  • 30
1

Try this, assuming you're using my answer here for the password

  observe({
    if (USER$Logged == FALSE) {

      output$page <- renderUI({
        div(class="outer",do.call(bootstrapPage,c("",ui1())))
      })
    }
    if (USER$Logged == TRUE) {
      output$page <- renderUI({
        div(class="outer",do.call(navbarPage,c(inverse=TRUE,title = "Contratulations you got in!",ui2())))
      })
      cat(paste0("Username: ",input$userName, "\n"))
      cat(paste0("Datum: ",Sys.time(), "\n"))
      print(ui)
    }
  })
Community
  • 1
  • 1
Pork Chop
  • 28,528
  • 5
  • 63
  • 77
  • Actually, this is what I am doing right now: `observe({ if (USER$Logged == TRUE) { cat(paste0(...)) } })`. userdata ist non reactive USER$Logger is however. – maRtin Dec 02 '16 at 14:37