Reputation: 6516
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?
Upvotes: 10
Views: 6044
Reputation: 2758
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 casescat("my output")
(i.e. printing to standard out) will work correctly, but in others (e.g. inside arenderPrint
, which usescapture.output
to redirect output), it won’t, so we recommend always sending trace output tostderr()
.
Upvotes: 12
Reputation: 29417
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)
}
})
Upvotes: 1