R Shiny Server:如何计算我的应用程序的用户数

Cau*_*chy 2 r shiny-server

我正在使用R shiny-server开源版本。我想计算应用程序的用户数。这是我的配置文件:

# 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;
  }
}
Run Code Online (Sandbox Code Playgroud)

当我使用我的应用程序并查看日志文件时,没有任何信息可以告诉我使用我的应用程序的IP /用户。有没有办法获取此信息?

Oga*_*anM 5

您可以使用此处列出的javascript插件。它允许您提取IP以及由杂项信息(例如浏览器,显示器大小等)组成的唯一指纹(哈希)。对于Shinyapps.io中的大多数用户,IP信息不可用,但您应该可以大致了解。请注意,如果同一个人使用不同的浏览器,您将获得不同的哈希值

关键部分正在添加

inputIp("ipid"),
inputUserid("fingerprint")
Run Code Online (Sandbox Code Playgroud)

到侧边栏布局中的某个位置。这些是收集所需信息所需的隐藏元素。

之后,他们可以作为观察员加入

observe({
    fingerprint <- input$fingerprint
    ipid <- input$ipid
})
Run Code Online (Sandbox Code Playgroud)

当然,您需要将.js文件复制到www / js文件夹

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

但是,要获得实际计数,您需要持久性文件存储。它在Shinyapps.io中不可用,但是您可以使用云存储选项(例如保管箱)来记录用户。有关此内容的教程,请参见http://shiny.rstudio.com/articles/persistent-data-storage.html。每当有人使用我的应用程序时,我个人都使用rdrop2编辑我的保管箱中的文件。