Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R shiny server: How to count number of users of my application

Tags:

r

shiny-server

I am using R shiny-server open source version. I want to count the number of users of my application. This is my configuration file:

# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;

# Define a server that listens on port 80
server {
  listen 80;

  server_name some_name;

  # Define a location at the base URL
  location / {

    # Host the directory of Shiny Apps stored in this directory
    site_dir /srv/shiny-server/;

    # Log all Shiny output to files in this directory
    log_dir /var/log/shiny-server;

    # When a user visits the base URL rather than a particular application,
    # an index of the applications available in this directory will be shown.
    directory_index on;
  }
}

When I use my application and I look in the log files, there is nothing that tells me of the IPs/users that used my application. Is there a way to get this information?

like image 962
Cauchy Avatar asked Mar 14 '23 17:03

Cauchy


1 Answers

You can use the javascript add ons listed here. It allows you to extract IPs and a unique fingerprint (a hash) composed of misc information such as browser, display size etc. For most users in shinyapps.io, IP information is unavailable but you should be able to get a rough count. Note that if same people use different browsers you'll get different hashes for them

The critical parts are adding

inputIp("ipid"),
inputUserid("fingerprint")

to somewhere in the sidebar layout. These are hidden elements required to collect the information you want.

After that they can be accesed in an observer as

observe({
    fingerprint <- input$fingerprint
    ipid <- input$ipid
})

And of course you need to copy the .js files to www/js folder

source: https://groups.google.com/forum/#!msg/shiny-discuss/EGQhEyoEk3E/ur0mpif11x4J

To get an actual count though, you need persistent file storage. This is not available in shinyapps.io, but you can use cloud storage options such as dropbox to log your users. A tutorial on this is available here http://shiny.rstudio.com/articles/persistent-data-storage.html. I personally use rdrop2 to edit a file in my dropbox every time someone uses my app.

like image 86
OganM Avatar answered Mar 17 '23 14:03

OganM