Knowing visitors identity on shiny R app

徘徊边缘 提交于 2020-01-15 04:26:07

问题


Is it possible to count the number of different visitors in an online shiny R app in time?

Thank you in advance


回答1:


You could define a reactive counter inside global.R that gets increased whenever a user connects and decreased whenever a user disconnects. Here is an example.

library(shiny)

# put this line in global.R in case you want to launch the app
# with runApp (from a directory) rather than shinyApp
nvisitors = reactiveVal(0)

server = function(input, output, session){
  nvisitors(isolate(nvisitors()) + 1)
  onSessionEnded(function(x){ 
    nvisitors(isolate(nvisitors()) - 1)
  })

  output$text = renderText({
    nvisitors()
  })
}

ui = shinyUI(
  textOutput("text")
)

shinyApp(ui, server)

Counting the total number of visitors is more challenging tough since you need to implement persistent data storage to do that properly.



来源:https://stackoverflow.com/questions/43051537/knowing-visitors-identity-on-shiny-r-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!