是否可以及时统计在线 Shiny R 应用程序中不同访问者的数量?
提前谢谢
最佳答案
您可以在 global.R
中定义一个 react 计数器,每当用户连接时该计数器就会增加,而每当用户断开连接时该计数器就会减少。这是一个例子。
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)
计算访客总数更具挑战性,因为您需要实现 persistent data storage正确地做到这一点。
关于javascript - 在 Shiny 的 R 应用程序上了解访客身份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43051537/