Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display R console logs on shiny server

Tags:

r

shiny

I am building shiny app for data analysis operations. Which is all working fine.

I want to know that is there any way to display logs i.e whats happening behind in R Studio. Like print() messages or whatever R console is printing. I need to display all this activity interactively in the shiny app.

Like when we print progress, is there any way to append progress messages instead of displaying new message.

I have searched on interned but unable find anything in this regard.

Has anyone done this kind of thing ? Any kind help can be appreciated.

like image 845
analyticalpicasso Avatar asked Feb 18 '15 09:02

analyticalpicasso


People also ask

How do I check R logs?

Windows: You can open an Explorer window to the log file directory by typing the following command into Start -> Run: For Windows Vista and 7+: %localappdata%\RStudio-Desktop\log. For Windows XP: %USERPROFILE%\Local Settings\Application Data\RStudio-Desktop\log.

How do you show a message in Shiny?

Simply call shinyalert() with the desired arguments, such as a title and text, and a modal will show up. In order to be able to call shinyalert() in a Shiny app, you must first call useShinyalert() anywhere in the app's UI.


1 Answers

Well there is probably a better way that works for R & R Shiny on your computer & R Shiny that runs on the Server -> library(log4r)

library(log4r)
loggerDebug <- create.logger()
logfile(loggerDebug) <- 'data/debugData.log'
level(loggerDebug) <- 'INFO'

loggerServer <- create.logger()
logfile(loggerServer) <- 'data/serverData.log'
level(loggerServer) <- 'INFO'

# examples of levels
# debug(logger, 'A Debugging Message') # Won't print anything
# info(logger, 'An Info Message')
# warn(logger, 'A Warning Message')
# error(logger, 'An Error Message')
# fatal(logger, 'A Fatal Error Message')

Be sure to have the correct read and write acces on the server else it will not work. (remember that the R Server is writing and not you)

# this depends on your security settings and rights
# talk to your UNIX ADMIN first
test <- list()
test$test <- "test"

# to change in linux / unix 
system("chmod a+rwx /...pathToYourApp..../data")
system("chmod a+rwx /...pathToYourApp..../data/debugData.log")

info(loggerDebug, paste('|   TEST   |',test$test,"|"))

# close after write (for security):
system("chmod u=-x,g-x,o-rwx /...pathToYourApp..../data")
system("chmod u=-x,g-x,o-rwx /...pathToYourApp..../data/debugData.log")

To be even more secure you can do:

system("chattr +a /...pathToYourApp..../data/debugData.log")

This only allows appending to the file so no modifications can be made to the existing content. (can help to convince the UNIX ADMIN)

You can open the log file while you are working, be sure to refresh or reopen the file if you use RStudio or use a more dynamic package that updates itself (like Sublime Text or .... )

I hope this is of help, perhaps you found an even better way, let us know

like image 103
irJvV Avatar answered Sep 22 '22 05:09

irJvV