Who touched my shiny-app? A feature to track user's behavior.

205 views
Skip to first unread message

Huidong TIAN

unread,
Feb 11, 2014, 9:20:46 AM2/11/14
to shiny-...@googlegroups.com
Hi Shiny-users,
  I wrote an app to show user's behavior which can be used to record who, when and what they have done to your app. I would like to share it with you guys: http://spark.rstudio.com/withr/tracking/

  For detail information, please visit my personal website: http://withr.me/blog/2014/02/11/who-touched-my-shiny-app/ and you are welcome to comment.

Best!

Huidong Tian

Vincent

unread,
Feb 11, 2014, 6:24:36 PM2/11/14
to shiny-...@googlegroups.com
Interesting. Can this information be captured per user with cookies or something like that or in an individual log file? On a related note could you save the json-stream in a per-user log file?

Huidong TIAN

unread,
Feb 12, 2014, 2:53:42 AM2/12/14
to shiny-...@googlegroups.com
Yes, I think. 

You can add this code in your server.R, like:

logTime <- format(Sys.time(), "%Y_%m_%d_%H_%M_%S");
fileLog <- paste("log", logTime, ".txt", sep = "")
file.create(fileLog)

This will create an empty txt file which can be used to save user behavior. Then add this code to write user behavior to that file:
observe({
  x <- iconv(input$tracking, from = "UTF-8")
  i <- as.numeric(regexpr("|", x, fixed = TRUE))
  L <- substr(x, 1, (i-1))
  V <- substr(x, (i+1), nchar(x)) 
  L <- paste('"', as.character(Sys.time()), " ", L, '": ', sep = "")
  if(grepl(",", V)) {
    V <- paste('["', gsub(",", '", "', V), '"],', sep = "")
  } else {
    V <- paste('"', V, '",', sep = "")
  } 
  write(paste(L, V, sep = ""), fileLog, append = TRUE)
})

Vincent

unread,
Feb 12, 2014, 2:45:21 PM2/12/14
to shiny-...@googlegroups.com
Cool. Thanks Huidong

Huidong TIAN

unread,
Feb 12, 2014, 2:49:02 PM2/12/14
to shiny-...@googlegroups.com
Hi Vincent,
  Just realized that we actually don't need to create a new Shiny bunding, we can just use the textInput. I will update the gist soon.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages