Title: | 'Shiny' App Usage Telemetry |
---|---|
Description: | Enables instrumentation of 'Shiny' apps for tracking user session events such as input changes, browser type, and session duration. These events can be sent to any of the available storage backends and analyzed using the included 'Shiny' app to gain insights about app usage and adoption. |
Authors: | André Veríssimo [aut, cre], Kamil Żyła [aut], Krystian Igras [aut], Recle Vibal [aut], Arun Kodati [aut], Wahaduzzaman Khan [aut], Appsilon Sp. z o.o. [cph] |
Maintainer: | André Veríssimo <[email protected]> |
License: | LGPL-3 |
Version: | 0.3.1.9001 |
Built: | 2025-02-11 05:59:13 UTC |
Source: | https://github.com/appsilon/shiny.telemetry |
Run example telemetry analytics dashboard
analytics_app(data_storage)
analytics_app(data_storage)
data_storage |
data_storage instance that will handle all backend read and writes. |
An object that represents the analytics app. Printing the object or
passing it to shiny::runApp()
will run it.
This is used in shiny.telemetry, but also externally with the Plumber endpoint.
build_id_from_secret(secret)
build_id_from_secret(secret)
secret |
string that contains information that should not be publicly available |
A string with an hash of the secret.
build_id_from_secret("some_random_secret_generated_with_uuid::UUIDgenerate")
build_id_from_secret("some_random_secret_generated_with_uuid::UUIDgenerate")
Function that takes creates a signature for the values
using a secret.
build_token(values, secret = NULL)
build_token(values, secret = NULL)
values |
R object that is going to be signed |
secret |
string that contains the shared secret to sign the communication. It can be NULL on both telemetry and in plumber API to disable this communication feature |
This is used in shiny.telemetry, but also externally with the Plumber endpoint.
A string that contains an hash to uniquely identify the parameters.
build_token(values = list(list(1, 2, 3), 2, 2, 3, "bb")) build_token(values = list(list(1, 2, 3), 1, 2, 3, "bb")) build_token(values = list(list(1, 2, 3), 1, 2, 3, "bb"), secret = "abc") build_token(values = list(list(1, 2, 3), 1, 2, 3, "bb"), secret = "abd")
build_token(values = list(list(1, 2, 3), 2, 2, 3, "bb")) build_token(values = list(list(1, 2, 3), 1, 2, 3, "bb")) build_token(values = list(list(1, 2, 3), 1, 2, 3, "bb"), secret = "abc") build_token(values = list(list(1, 2, 3), 1, 2, 3, "bb"), secret = "abd")
Abstract R6 Class that encapsulates all the operations needed by Shiny.telemetry to read and write. This removes the complexity from the functions and uses a unified API.
event_bucket
string that identifies the bucket to store user related and action data
new()
initialize data storage object common with all providers
DataStorage$new()
insert()
Insert new data
DataStorage$insert(app_name, type, session = NULL, details = NULL, time = NULL)
app_name
string with name of dashboard (the version can be also included in this string)
type
string that identifies the event type to store
session
(optional) string that identifies a session where the event was logged
details
atomic element of list with data to save in storage
time
date time value indicates the moment the record was
generated in UTC. By default it should be NULL and determined
automatically, but in cases where it should be defined, use Sys.time()
or lubridate::now(tzone = "UTC")
to generate it.
Nothing. This method is called for side effects.
read_event_data()
read all user data from SQLite.
DataStorage$read_event_data(date_from = NULL, date_to = NULL, app_name = NULL)
date_from
(optional) date representing the starting day of results.
date_to
(optional) date representing the last day of results.
app_name
(optional) string identifying the Dashboard-specific event data
close()
Close the connection if necessary
DataStorage$close()
clone()
The objects of this class are cloneable with this method.
DataStorage$clone(deep = FALSE)
deep
Whether to make a deep clone.
JSON
Log FileImplementation of the DataStorage
R6 class to a JSON
log file backend using a unified
API for read/write operations
shiny.telemetry::DataStorage
-> DataStorageLogFile
event_bucket
string that identifies the file path to store user related and action data
new()
Initialize the data storage class
DataStorageLogFile$new(log_file_path)
log_file_path
string with path to JSON
log file user actions
clone()
The objects of this class are cloneable with this method.
DataStorageLogFile$clone(deep = FALSE)
deep
Whether to make a deep clone.
log_file_path <- tempfile(fileext = ".txt") data_storage <- DataStorageLogFile$new(log_file_path = log_file_path) data_storage$insert("example", "test_event", "session1") data_storage$insert("example", "input", "s1", list(id = "id")) data_storage$insert("example", "input", "s1", list(id = "id2", value = 32)) data_storage$insert( "example", "test_event_3_days_ago", "session1", time = lubridate::as_datetime(lubridate::today() - 3) ) data_storage$read_event_data() data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1) file.remove(log_file_path)
log_file_path <- tempfile(fileext = ".txt") data_storage <- DataStorageLogFile$new(log_file_path = log_file_path) data_storage$insert("example", "test_event", "session1") data_storage$insert("example", "input", "s1", list(id = "id")) data_storage$insert("example", "input", "s1", list(id = "id2", value = 32)) data_storage$insert( "example", "test_event_3_days_ago", "session1", time = lubridate::as_datetime(lubridate::today() - 3) ) data_storage$read_event_data() data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1) file.remove(log_file_path)
Implementation of the DataStorage
R6 class to MariaDB backend using a
unified API for read/write operations
shiny.telemetry::DataStorage
-> shiny.telemetry::DataStorageSQLFamily
-> DataStorageMariaDB
new()
Initialize the data storage class
DataStorageMariaDB$new( username = NULL, password = NULL, hostname = "127.0.0.1", port = 3306, dbname = "shiny_telemetry" )
username
string with a MariaDB username.
password
string with the password for the username.
hostname
string with hostname of MariaDB instance.
port
numeric value with the port number of MariaDB instance.
dbname
string with the name of the database in the MariaDB instance.
clone()
The objects of this class are cloneable with this method.
DataStorageMariaDB$clone(deep = FALSE)
deep
Whether to make a deep clone.
## Not run: data_storage <- DataStorageMariaDB$new(user = "mariadb", password = "mysecretpassword") data_storage$insert("example", "test_event", "session1") data_storage$insert("example", "input", "s1", list(id = "id1")) data_storage$insert("example", "input", "s1", list(id = "id2", value = 32)) data_storage$insert( "example", "test_event_3_days_ago", "session1", time = lubridate::as_datetime(lubridate::today() - 3) ) data_storage$read_event_data() data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1) data_storage$close() ## End(Not run)
## Not run: data_storage <- DataStorageMariaDB$new(user = "mariadb", password = "mysecretpassword") data_storage$insert("example", "test_event", "session1") data_storage$insert("example", "input", "s1", list(id = "id1")) data_storage$insert("example", "input", "s1", list(id = "id2", value = 32)) data_storage$insert( "example", "test_event_3_days_ago", "session1", time = lubridate::as_datetime(lubridate::today() - 3) ) data_storage$read_event_data() data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1) data_storage$close() ## End(Not run)
Implementation of the DataStorage
R6 class to MongoDB backend using a
unified API for read/write operations
shiny.telemetry::DataStorage
-> DataStorageMongoDB
new()
Initialize the data storage class
DataStorageMongoDB$new( hostname = "localhost", port = 27017, username = NULL, password = NULL, authdb = NULL, dbname = "shiny_telemetry", options = NULL, ssl_options = mongolite::ssl_options() )
hostname
the hostname or IP address of the MongoDB server.
port
the port number of the MongoDB server (default is 27017).
username
the username for authentication (optional).
password
the password for authentication (optional).
authdb
the default authentication database (optional).
dbname
name of database (default is "shiny_telemetry").
options
Additional connection options in a named list format (e.g., list(ssl = "true", replicaSet = "myreplicaset")) (optional).
ssl_options
additional connection options such as SSL keys/certs
(default is mongolite::ssl_options()
).
clone()
The objects of this class are cloneable with this method.
DataStorageMongoDB$clone(deep = FALSE)
deep
Whether to make a deep clone.
## Not run: data_storage <- DataStorageMongoDB$new( host = "localhost", db = "test", ssl_options = mongolite::ssl_options() ) data_storage$insert("example", "test_event", "session1") data_storage$insert("example", "input", "s1", list(id = "id1")) data_storage$insert("example", "input", "s1", list(id = "id2", value = 32)) data_storage$insert( "example", "test_event_3_days_ago", "session1", time = lubridate::as_datetime(lubridate::today() - 3) ) data_storage$read_event_data() data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1) data_storage$close() ## End(Not run)
## Not run: data_storage <- DataStorageMongoDB$new( host = "localhost", db = "test", ssl_options = mongolite::ssl_options() ) data_storage$insert("example", "test_event", "session1") data_storage$insert("example", "input", "s1", list(id = "id1")) data_storage$insert("example", "input", "s1", list(id = "id2", value = 32)) data_storage$insert( "example", "test_event_3_days_ago", "session1", time = lubridate::as_datetime(lubridate::today() - 3) ) data_storage$read_event_data() data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1) data_storage$close() ## End(Not run)
Implementation of the DataStorage
R6 class to MS SQL Server backend using a
unified API for read/write operations. This provider requires a configured
and named ODBC
driver to be set up on your system, for example, "ODBC
Driver 17 for SQL Server" or "ODBC
Driver 18 for SQL Server".
Note that MS SQL Server support requires a subtly different database schema:
the time
field is stored as a DATETIME
rather than a TIMESTAMP
.
shiny.telemetry::DataStorage
-> shiny.telemetry::DataStorageSQLFamily
-> DataStorageMSSQLServer
new()
Initialize the data storage class
DataStorageMSSQLServer$new( username = NULL, password = NULL, hostname = "127.0.0.1", port = 1433, dbname = "shiny_telemetry", driver = "ODBC Driver 17 for SQL Server", trust_server_certificate = "NO" )
username
string with a MS SQL Server username.
password
string with the password for the username.
hostname
string with hostname of the MS SQL Server instance.
port
numeric value with the port number of MS SQL Server instance.
dbname
string with the name of the database in the MS SQL Server instance.
driver
string with the name of the ODBC
driver class for MS SQL,
for example "ODBC
Driver 17 for SQL Server".
trust_server_certificate
string with "NO" or "YES", setting whether or not to trust the server's certificate implicitly.
clone()
The objects of this class are cloneable with this method.
DataStorageMSSQLServer$clone(deep = FALSE)
deep
Whether to make a deep clone.
## Not run: data_storage <- DataStorageMSSQLServer$new( user = "sa", password = "my-Secr3t_Password", hostname = "localhost", port = 1433, dbname = "shiny_telemetry", driver = "ODBC Driver 18 for SQL Server", trust_server_certificate = "YES" ) data_storage$insert("example", "test_event", "session1") data_storage$insert("example", "input", "s1", list(id = "id1")) data_storage$insert("example", "input", "s1", list(id = "id2", value = 32)) data_storage$insert( "example", "test_event_3_days_ago", "session1", time = lubridate::as_datetime(lubridate::today() - 3) ) data_storage$read_event_data() data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1) data_storage$close() ## End(Not run)
## Not run: data_storage <- DataStorageMSSQLServer$new( user = "sa", password = "my-Secr3t_Password", hostname = "localhost", port = 1433, dbname = "shiny_telemetry", driver = "ODBC Driver 18 for SQL Server", trust_server_certificate = "YES" ) data_storage$insert("example", "test_event", "session1") data_storage$insert("example", "input", "s1", list(id = "id1")) data_storage$insert("example", "input", "s1", list(id = "id2", value = 32)) data_storage$insert( "example", "test_event_3_days_ago", "session1", time = lubridate::as_datetime(lubridate::today() - 3) ) data_storage$read_event_data() data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1) data_storage$close() ## End(Not run)
Implementation of the DataStorage
R6 class to SQLite backend using a unified
API for read/write operations
shiny.telemetry::DataStorage
-> DataStoragePlumber
event_read_endpoint
string field that returns read action endpoint
event_insert_endpoint
string field that returns insert action endpoint
new()
Initialize the data storage class
DataStoragePlumber$new( hostname = "127.0.0.1", port = 80, protocol = "http", path = NULL, secret = NULL, authorization = NULL )
hostname
string with hostname of plumber instance,
port
numeric value with port number of plumber instance.
protocol
string with protocol of the connection of the plumber instance.
path
string with sub-path of plumber deployment.
secret
string with secret to sign communication with plumber (can be NULL for disabling communication signing).
authorization
string to use in HTTP headers for authorization (for example: to authenticate to a plumber deployment behind a connect server).
clone()
The objects of this class are cloneable with this method.
DataStoragePlumber$clone(deep = FALSE)
deep
Whether to make a deep clone.
## Not run: # Make sure the PLUMBER_SECRET environment variable is valid before # running these examples (NULL or a valid secret) data_storage <- DataStoragePlumber$new( hostname = "connect.appsilon.com", path = "shiny_telemetry_plumber", port = 443, protocol = "https", authorization = Sys.getenv("CONNECT_AUTHORIZATION_KEY"), secret = Sys.getenv("PLUMBER_SECRET") ) data_storage <- DataStoragePlumber$new( hostname = "127.0.0.1", path = NULL, port = 8087, protocol = "http", secret = Sys.getenv("PLUMBER_SECRET") ) data_storage$insert("example", "test_event", "session1") data_storage$insert("example", "input", "s1", list(id = "id")) data_storage$insert("example", "input", "s1", list(id = "id2", value = 32)) data_storage$insert( "example", "test_event_3_days_ago", "session1", time = lubridate::as_datetime(lubridate::today() - 3) ) data_storage$read_event_data() data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1) ## End(Not run)
## Not run: # Make sure the PLUMBER_SECRET environment variable is valid before # running these examples (NULL or a valid secret) data_storage <- DataStoragePlumber$new( hostname = "connect.appsilon.com", path = "shiny_telemetry_plumber", port = 443, protocol = "https", authorization = Sys.getenv("CONNECT_AUTHORIZATION_KEY"), secret = Sys.getenv("PLUMBER_SECRET") ) data_storage <- DataStoragePlumber$new( hostname = "127.0.0.1", path = NULL, port = 8087, protocol = "http", secret = Sys.getenv("PLUMBER_SECRET") ) data_storage$insert("example", "test_event", "session1") data_storage$insert("example", "input", "s1", list(id = "id")) data_storage$insert("example", "input", "s1", list(id = "id2", value = 32)) data_storage$insert( "example", "test_event_3_days_ago", "session1", time = lubridate::as_datetime(lubridate::today() - 3) ) data_storage$read_event_data() data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1) ## End(Not run)
Implementation of the DataStorage
R6 class to PostgreSQL backend using a
unified API for read/write operations
shiny.telemetry::DataStorage
-> shiny.telemetry::DataStorageSQLFamily
-> DataStoragePostgreSQL
new()
Initialize the data storage class
DataStoragePostgreSQL$new( username = NULL, password = NULL, hostname = "127.0.0.1", port = 5432, dbname = "shiny_telemetry", driver = "RPostgreSQL" )
username
string with a PostgreSQL username.
password
string with the password for the username.
hostname
string with hostname of PostgreSQL instance.
port
numeric value with the port number of PostgreSQL instance.
dbname
string with the name of the database in the PostgreSQL instance.
driver
string, to select PostgreSQL driver among c("RPostgreSQL", "RPostgres")
.
clone()
The objects of this class are cloneable with this method.
DataStoragePostgreSQL$clone(deep = FALSE)
deep
Whether to make a deep clone.
## Not run: data_storage <- DataStoragePostgreSQL$new(user = "postgres", password = "mysecretpassword") data_storage$insert("example", "test_event", "session1") data_storage$insert("example", "input", "s1", list(id = "id1")) data_storage$insert("example", "input", "s1", list(id = "id2", value = 32)) data_storage$insert( "example", "test_event_3_days_ago", "session1", time = lubridate::as_datetime(lubridate::today() - 3) ) data_storage$read_event_data() data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1) data_storage$close() ## End(Not run)
## Not run: data_storage <- DataStoragePostgreSQL$new(user = "postgres", password = "mysecretpassword") data_storage$insert("example", "test_event", "session1") data_storage$insert("example", "input", "s1", list(id = "id1")) data_storage$insert("example", "input", "s1", list(id = "id2", value = 32)) data_storage$insert( "example", "test_event_3_days_ago", "session1", time = lubridate::as_datetime(lubridate::today() - 3) ) data_storage$read_event_data() data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1) data_storage$close() ## End(Not run)
Abstract subclass of the DataStorage
R6 class for the SQL family of
providers
shiny.telemetry::DataStorage
-> DataStorageSQLFamily
clone()
The objects of this class are cloneable with this method.
DataStorageSQLFamily$clone(deep = FALSE)
deep
Whether to make a deep clone.
Implementation of the DataStorage
R6 class to SQLite backend using a unified
API for read/write operations
shiny.telemetry::DataStorage
-> shiny.telemetry::DataStorageSQLFamily
-> DataStorageSQLite
new()
Initialize the data storage class
DataStorageSQLite$new(db_path = "user_stats.sqlite")
db_path
string with path to SQLite
file.
clone()
The objects of this class are cloneable with this method.
DataStorageSQLite$clone(deep = FALSE)
deep
Whether to make a deep clone.
db_path <- tempfile(fileext = ".sqlite") data_storage <- DataStorageSQLite$new(db_path = db_path) data_storage$insert("example", "test_event", "session1") data_storage$insert("example", "input", "s1", list(id = "id1")) data_storage$insert("example", "input", "s1", list(id = "id2", value = 32)) data_storage$insert( "example", "test_event_3_days_ago", "session1", time = lubridate::as_datetime(lubridate::today() - 3) ) data_storage$read_event_data() data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1) file.remove(db_path)
db_path <- tempfile(fileext = ".sqlite") data_storage <- DataStorageSQLite$new(db_path = db_path) data_storage$insert("example", "test_event", "session1") data_storage$insert("example", "input", "s1", list(id = "id1")) data_storage$insert("example", "input", "s1", list(id = "id2", value = 32)) data_storage$insert( "example", "test_event_3_days_ago", "session1", time = lubridate::as_datetime(lubridate::today() - 3) ) data_storage$read_event_data() data_storage$read_event_data(Sys.Date() - 1, Sys.Date() + 1) file.remove(db_path)
Common date_from to recognize as NULL
date_from_null
date_from_null
An object of class character
of length 1.
Common date_to to recognize as NULL
date_to_null
date_to_null
An object of class character
of length 1.
An instance of this class will define metadata and data storage provider for gathering telemetry analytics of a Shiny dashboard.
The name
and version
parameters will describe the dashboard name and
version to track using analytics, allowing to store the analytics data from
multiple dashboards in the same data storage provider. As well as
discriminate different versions of the dashboard.
The default data storage provider uses a local SQLite database, but this
can be customizable when instantiating the class, by using another one of
the supported providers (see DataStorage
).
Events are logged at the DEBUG
level using the logger
package.
To see the logs, you can set:
logger::log_threshold("DEBUG", namespace = "shiny.telemetry")
data_storage
instance of a class that inherits from
DataStorage
. See the documentation on that class for more information.
app_name
string with name of dashboard
new()
Constructor that initializes Telemetry instance with parameters.
Telemetry$new( app_name = "(dashboard)", data_storage = DataStorageSQLite$new(db_path = file.path("telemetry.sqlite")) )
app_name
(optional) string that identifies the name of the dashboard.
By default it will store data with (dashboard)
.
data_storage
(optional) DataStorage
instance where telemetry
data is being stored.
It can take any of data storage providers by this package,
By default it will store in a SQLite local database in the current
working directory with filename telemetry.sqlite
version
(optional) string that identifies the version of the
dashboard. By default it will use v0.0.0
.
start_session()
Setup basic telemetry
Telemetry$start_session( track_inputs = TRUE, track_values = FALSE, login = TRUE, logout = TRUE, browser_version = TRUE, navigation_input_id = NULL, session = shiny::getDefaultReactiveDomain(), username = NULL, track_anonymous_user = TRUE, track_errors = TRUE )
track_inputs
flag that indicates if the basic telemetry should
track the inputs that change value. TRUE
by default
track_values
flag that indicates if the basic telemetry should
track the values of the inputs that are changing. FALSE
by default.
This parameter is ignored if track_inputs
is FALSE
login
flag that indicates if the basic telemetry should
track when a session starts. TRUE
by default.
logout
flag that indicates if the basic telemetry should
track when the session ends. TRUE
by default.
browser_version
flag that indicates that the browser version
should be tracked.TRUE
by default.
navigation_input_id
string or vector of strings that represent input ids and which value should be tracked as navigation events. i.e. a change in the value represent a navigation to a page or tab. By default, no navigation is tracked.
session
ShinySession
object or NULL to identify the current
Shiny session.
username
Character with username. If set, it will overwrite username from session object.
track_anonymous_user
flag that indicates to track anonymous user.
A cookie is used to track same user without login over multiple sessions,
This is only activated if none of the automatic methods produce a username
and when a username is not explicitly defined.TRUE
by default.
track_errors
flag that indicates if the basic telemetry should
track the errors. TRUE
by default. if using shiny version < 1.8.1
,
it can auto log errors only in UI output functions.
By using latest versions of shiny, it can auto log all types of errors.
Nothing. This method is called for side effects.
log_navigation()
Log an input change as a navigation event
Telemetry$log_navigation(input_id, session = shiny::getDefaultReactiveDomain())
input_id
string that identifies the generic input in the Shiny application so that the function can track and log changes to it.
session
ShinySession
object or NULL to identify the current
Shiny session.
Nothing. This method is called for side effects.
log_navigation_manual()
Log a navigation event manually by indicating the id (as input id)
Telemetry$log_navigation_manual( navigation_id, value, session = shiny::getDefaultReactiveDomain() )
navigation_id
string that identifies navigation event.
value
string that indicates a value for the navigation
session
ShinySession
object or NULL to identify the current
Shiny session.
Nothing. This method is called for side effects.
log_login()
Log when session starts
Telemetry$log_login( username = NULL, session = shiny::getDefaultReactiveDomain() )
username
string with username from current session
session
ShinySession
object or NULL to identify the current
Shiny session.
Nothing. This method is called for side effects.
log_logout()
Log when session ends
Telemetry$log_logout( username = NULL, session = shiny::getDefaultReactiveDomain() )
username
string with username from current session
session
ShinySession
object or NULL to identify the current
Shiny session.
Nothing. This method is called for side effects.
log_click()
Log an action click
Telemetry$log_click(id, session = shiny::getDefaultReactiveDomain())
id
string that identifies a manual click to the dashboard.
session
ShinySession
object or NULL to identify the current
Shiny session.
Nothing. This method is called for side effects.
log_browser_version()
Log the browser version
Telemetry$log_browser_version(session = shiny::getDefaultReactiveDomain())
session
ShinySession
object or NULL to identify the current
Shiny session.
Nothing. This method is called for side effects.
log_button()
Track a button and track changes to this input (without storing the values)
Telemetry$log_button( input_id, track_value = FALSE, session = shiny::getDefaultReactiveDomain() )
input_id
string that identifies the button in the Shiny application so that the function can track and log changes to it.
track_value
flag that indicates if the basic telemetry should
track the value of the input that are changing. FALSE
by default.
session
ShinySession
object or NULL to identify the current
Shiny session.
Nothing. This method is called for side effects.
log_all_inputs()
Automatic tracking of all input changes in the App. Depending on the
parameters, it may only track a subset of inputs by excluding patterns
or by including specific vector of input_ids
.
Telemetry$log_all_inputs( track_values = FALSE, excluded_inputs = c("browser_version"), excluded_inputs_regex = NULL, include_input_ids = NULL, session = shiny::getDefaultReactiveDomain() )
track_values
flag that indicates if the basic telemetry should
track the values of the inputs that are changing. FALSE
by default.
This parameter is ignored if track_inputs
is FALSE
.
excluded_inputs
vector of input_ids that should not be tracked. By default it doesn't track browser version, which is added by this package.
excluded_inputs_regex
vector of input_ids that should not be tracked. All Special characters will be escaped.
include_input_ids
vector of input_ids that will be tracked. This input_ids should be an exact match and will be given priority over exclude list.
session
ShinySession
object or NULL to identify the current
Shiny session.
Nothing. This method is called for side effects.
log_input()
Track changes of a specific input id.
Telemetry$log_input( input_id, track_value = FALSE, matching_values = NULL, input_type = "text", session = shiny::getDefaultReactiveDomain() )
input_id
string (or vector of strings) that identifies the generic input in the Shiny application so that the function can track and log changes to it.
When the input_id
is a vector of strings, the function will behave just
as calling log_input
one by one with the same arguments.
track_value
flag that indicates if the basic telemetry should
track the value of the input that are changing. FALSE
by default.
matching_values
An object specified possible values to register.
input_type
"text"
to registered bare input value, "json"
to parse
value from JSON
format.
session
ShinySession
object or NULL to identify the current
Shiny session.
Nothing. This method is called for its side effects.
log_input_manual()
Log a manual input value.
This can be called in telemetry and is also used as a layer between log_input family of functions and actual log event. It creates the correct payload to log the event internally.
Telemetry$log_input_manual( input_id, value = NULL, session = shiny::getDefaultReactiveDomain() )
input_id
string that identifies the generic input in the Shiny application so that the function can track and log changes to it.
value
(optional) scalar value or list with the value to register.
session
ShinySession
object or NULL to identify the current
Shiny session.
Nothing. This method is called for side effects.
log_custom_event()
Log a manual event
Telemetry$log_custom_event( event_type, details = NULL, session = shiny::getDefaultReactiveDomain() )
event_type
string that identifies the event type
details
(optional) scalar value or list with the value to register.
session
ShinySession
object or NULL to identify the current
Shiny session.
Nothing. This method is called for side effects.
log_error()
Log a manual error event
Telemetry$log_error( output_id, message, session = shiny::getDefaultReactiveDomain() )
output_id
string that refers to the output element where the error occurred.
message
string that describes the error.
session
ShinySession
object or NULL to identify the current Shiny session.
Nothing. This method is called for side effects.
log_errors()
Track errors as they occur in observe and reactive
Telemetry$log_errors(session = shiny::getDefaultReactiveDomain())
session
ShinySession
object or NULL to identify the current Shiny session.
Nothing. This method is called for side effects.
clone()
The objects of this class are cloneable with this method.
Telemetry$clone(deep = FALSE)
deep
Whether to make a deep clone.
DataStorage
which this function wraps.
log_file_path <- tempfile(fileext = ".txt") telemetry <- Telemetry$new( data_storage = DataStorageLogFile$new(log_file_path = log_file_path) ) # 1. Initialize telemetry with default options # # Use in a shiny application if (interactive()) { library(shiny) shinyApp( ui = fluidPage( use_telemetry(), # 2. Add necessary javascript to Shiny numericInput("n", "n", 1), plotOutput('plot') ), server = function(input, output) { telemetry$start_session() # 3. Minimal setup to track events output$plot <- renderPlot({ hist(runif(input$n)) }) } ) } # # Manual logging of Telemetry that can be used inside Shiny Application # to further customize the events to be tracked. session <- shiny::MockShinySession$new() # Create dummy session (only for example purposes) class(session) <- c(class(session), "ShinySession") telemetry$log_click("a_button", session = session) telemetry$log_error("global", message = "An error has occured") telemetry$log_custom_event("a_button", list(value = 2023), session = session) telemetry$log_custom_event("a_button", list(custom_field = 23), session = session) # Manual call login with custom username telemetry$log_login("ben", session = session) # Read all data telemetry$data_storage$read_event_data() file.remove(log_file_path) # # Using SQLite db_path <- tempfile(fileext = ".sqlite") telemetry_sqlite <- Telemetry$new( data_storage = DataStorageSQLite$new(db_path = db_path) ) telemetry_sqlite$log_custom_event("a_button", list(value = 2023), session = session) telemetry_sqlite$log_custom_event("a_button", list(custom_field = 23), session = session) # Read all data from time range telemetry_sqlite$data_storage$read_event_data("2020-01-01", "2055-01-01") file.remove(db_path)
log_file_path <- tempfile(fileext = ".txt") telemetry <- Telemetry$new( data_storage = DataStorageLogFile$new(log_file_path = log_file_path) ) # 1. Initialize telemetry with default options # # Use in a shiny application if (interactive()) { library(shiny) shinyApp( ui = fluidPage( use_telemetry(), # 2. Add necessary javascript to Shiny numericInput("n", "n", 1), plotOutput('plot') ), server = function(input, output) { telemetry$start_session() # 3. Minimal setup to track events output$plot <- renderPlot({ hist(runif(input$n)) }) } ) } # # Manual logging of Telemetry that can be used inside Shiny Application # to further customize the events to be tracked. session <- shiny::MockShinySession$new() # Create dummy session (only for example purposes) class(session) <- c(class(session), "ShinySession") telemetry$log_click("a_button", session = session) telemetry$log_error("global", message = "An error has occured") telemetry$log_custom_event("a_button", list(value = 2023), session = session) telemetry$log_custom_event("a_button", list(custom_field = 23), session = session) # Manual call login with custom username telemetry$log_login("ben", session = session) # Read all data telemetry$data_storage$read_event_data() file.remove(log_file_path) # # Using SQLite db_path <- tempfile(fileext = ".sqlite") telemetry_sqlite <- Telemetry$new( data_storage = DataStorageSQLite$new(db_path = db_path) ) telemetry_sqlite$log_custom_event("a_button", list(value = 2023), session = session) telemetry_sqlite$log_custom_event("a_button", list(custom_field = 23), session = session) # Read all data from time range telemetry_sqlite$data_storage$read_event_data("2020-01-01", "2055-01-01") file.remove(db_path)
Function that adds telemetry HTML elements to UI
use_telemetry(id = "")
use_telemetry(id = "")
id |
(optional) string with id representing the namespace |
A shiny.tag
object to be included in the UI of a Shiny app.