Easy logging of users activity and session events of your Shiny App
The shiny.telemetry
R package tracks events occurring on
a user session, such as input changes and session duration, and stores
them in a local or remote database.
It provides developers with the tools to help understand how users interact with Shiny dashboards and answer questions such as: which tabs/pages are more often visited, which inputs users are changing, what is the average length of a session, etc.
The shiny.telemetry
package can be installed from GitHub
by using the remotes package:
::install_github("Appsilon/shiny.telemetry", dependencies = TRUE) remotes
With dependencies = TRUE
the suggested packages
(required to run some examples) will be installed in addition to
mandatory dependencies.
shiny.telemetry
allows for a minimal setup with only 3
commands that can track some information about the session:
The code below runs a minimal example of a Shiny application that
uses shiny.telemetry
. The package will keep track of the
session information and all changes to the
numericInput
.
Note: When using the dashboard nothing is happening from the user’s perspective as all operation run in the background (either in the server or in Javascript).
library(shiny)
library(shiny.telemetry)
<- Telemetry$new() # 1. Initialize telemetry with default options
telemetry
shinyApp(
ui = fluidPage(
use_telemetry(), # 2. Add necessary javascript to Shiny
numericInput("n", "n", 1),
plotOutput('plot')
),server = function(input, output) {
$start_session() # 3. Minimal setup to track events
telemetry$plot <- renderPlot({ hist(runif(input$n)) })
output
} )
When inspecting the code above, we can breakdown the 3 lines of code by:
Telemetry
object that is used across the
different sessionsuse_telemetry()
. It is used to track browser version.start_session()
of the Telemetry
object.The developers and administrators of the dashboard can access the
data that is gathered by shiny.telemetry
via a Telemetry
object or directly from DataStorage
via the appropriate
provider.
# After running the instrumented app
::Telemetry$new()$data_storage$read_event_data("2020-01-01", "2050-01-01")
shiny.telemetry
# Default provider and path for Telemetry$new()
::DataStorageSQLite$new(db_path = "telemetry.sqlite")$read_event_data("2020-01-01", "2050-01-01") shiny.telemetry
The package includes an analytics dashboard to view the data. It is
located at inst/examples/app/analytics
and it should be
modified so that it references the correct DataStorage
provider and configuration.
There are 3 different types of data providers that can range from local filesystem storage to a remote Plumber REST API instance.
DataStorageSQLite
classDataStorageLogFile
classDataStorageMariaDB
classDataStoragePostgreSQL
classDataStorageMSSQLServer
classDataStoragePlumber
class
The setup for plumber requires a valid Plumber instance running on the network and the communication can be protected. See Plumber deployment documentation for more information.
The package uses the logger
package internally with the
shiny.telemetry
namespace. To debug the
shiny.telemetry
calls in the dashboard, change the
threshold of this namespace to DEBUG
:
::log_threshold("DEBUG", namespace = "shiny.telemetry") logger
note: This command can be run before the Shiny call or by
adding it to the .Rprofile
.
See CONTRIBUTING.
Appsilon is a Posit (formerly RStudio) Full Service Certified
Partner.
Learn more at appsilon.com.
Get in touch opensource@appsilon.com
Explore the Rhinoverse - a family of R packages built around Rhino!