User Management
users.Rmd
Every event is associated with a user.
Set user
When a user visits your application for the first time they are assigned a random user id that is stored as cookie
, this ID always starts in smu_
and you will be able to see those in your dashboards.
However, you can also set that user yourself, e.g.: if your application requires authentication or it runs in an environment where the user is already authenticated (e.g.: Posit Connect).
library(shiny)
library(shinymetrics)
tracker <- Shinymetrics$new()$track_recommended()
ui <- fluidPage(
tracker$include(),
textInput("username"),
actionButton("login", "Log in")
)
server <- function(input, output, session) {
shinymetrics_server()
observeEvent(input$login, {
shinymetrics_set_user(input$username)
})
}
shinyApp(ui, server)
Note that, like the default username created by shinymetrics, this is also stored as cookie so there is no need to set the user at every session.
If you are using Posit Connect you should be able to access the authenticated user from the session
object with session$user
.