### Install Shiny Telemetry Dependencies in R Source: https://github.com/appsilon/shiny.telemetry/blob/main/inst/examples/app/README.md Installs the 'shiny.telemetry', 'dplyr', and 'config' R packages required to run the example application. This ensures all necessary components for telemetry tracking and data manipulation are available. ```r install.packages( c( "shiny.telemetry", "dplyr", "config" ), dependencies = c("Depends", "Imports", "Suggests") ) ``` -------------------------------- ### Run Shiny Application with shiny.telemetry in R Source: https://github.com/appsilon/shiny.telemetry/blob/main/inst/examples/app/README.md Starts the Shiny application for testing shiny.telemetry. This command executes the R/Shiny app, enabling input tracking and data collection by the telemetry package. ```r shiny::runApp("instrumentation") ``` -------------------------------- ### Install pre-commit using the precommit R package Source: https://github.com/appsilon/shiny.telemetry/blob/main/CONTRIBUTING.md Installs the pre-commit tool by following the installation guide for the `{precommit}` R package. This method is specific to R users. ```r # Follow the installation section in the precommit package vignette: # https://lorenzwalthert.github.io/precommit/articles/precommit.html#installation ``` -------------------------------- ### Install shiny.telemetry Package from GitHub Source: https://github.com/appsilon/shiny.telemetry/blob/main/README.md Installs the shiny.telemetry package from GitHub, including optional dependencies for running examples. This is the primary method for obtaining the package. ```r remotes::install_github("Appsilon/shiny.telemetry", dependencies = TRUE) ``` -------------------------------- ### Install pre-commit using Homebrew Source: https://github.com/appsilon/shiny.telemetry/blob/main/CONTRIBUTING.md Installs the pre-commit tool using the Homebrew package manager. This is an alternative installation method for macOS users. ```bash brew install pre-commit ``` -------------------------------- ### Basic Shiny App with shiny.telemetry Integration Source: https://github.com/appsilon/shiny.telemetry/blob/main/README.md Demonstrates a minimal Shiny application setup using shiny.telemetry. It initializes telemetry, adds necessary JavaScript for tracking browser information, and starts session tracking to log events like input changes and session duration. ```r library(shiny) library(shiny.telemetry) telemetry <- Telemetry$new() # 1. Initialize telemetry with default options 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)) }) } ) ``` -------------------------------- ### Set up pre-commit hooks Source: https://github.com/appsilon/shiny.telemetry/blob/main/CONTRIBUTING.md Installs the git hooks for the project after pre-commit has been installed. This command enables the automated checks before each commit. ```bash pre-commit install ``` -------------------------------- ### Install pre-commit using pip Source: https://github.com/appsilon/shiny.telemetry/blob/main/CONTRIBUTING.md Installs the pre-commit tool using pip, the Python package installer. This is a prerequisite for using pre-commit hooks in the project. ```bash pip install pre-commit ``` ```bash pip3 install pre-commit ``` -------------------------------- ### Install Dependencies for Plumber API Source: https://github.com/appsilon/shiny.telemetry/blob/main/plumber_rest_api/README.md Installs the required R packages for the Plumber API using the `renv` package manager. This ensures all dependencies are met for the API to run correctly. ```R > renv::restore() ``` -------------------------------- ### Start Plumber API Instance Source: https://github.com/appsilon/shiny.telemetry/blob/main/plumber_rest_api/README.md Starts the Plumber REST API service. This can be done by sourcing the `plumber.R` file or by directly calling the `plumber::plumb()` function with the API's main file. ```R # source("plumber.R") > plumber::plumb("plumber.R") ``` -------------------------------- ### Configure MariaDB/MySQL Storage Backend for Telemetry in R Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Configures the shiny.telemetry package to connect to a MariaDB or MySQL database for centralized data storage. This snippet demonstrates initialization and provides an example of integrating telemetry into a Shiny application with event logging. Requires the 'shiny.telemetry' and 'shiny' libraries. ```r library(shiny.telemetry) # Initialize with MariaDB backend data_storage <- DataStorageMariaDB$new( username = "telemetry_user", password = "secure_password", hostname = "mariadb.internal.net", port = 3306, dbname = "analytics_db" ) telemetry <- Telemetry$new( app_name = "EnterpriseApp", data_storage = data_storage ) # Example usage in Shiny library(shiny) shinyApp( ui = fluidPage( use_telemetry(), textInput("search", "Search"), actionButton("submit", "Submit") ), server = function(input, output, session) { telemetry$start_session(track_values = TRUE) observeEvent(input$submit, { telemetry$log_click("submit") }) } ) ``` -------------------------------- ### Configure PostgreSQL Storage Backend for Telemetry in R Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Sets up the shiny.telemetry package to use PostgreSQL as its data storage backend. This configuration is suitable for production environments and includes examples for inserting and reading event data, as well as closing the database connection. Requires the 'shiny.telemetry' library. ```r library(shiny.telemetry) # Initialize with PostgreSQL backend data_storage <- DataStoragePostgreSQL$new( username = "postgres", password = "mysecretpassword", hostname = "db.example.com", port = 5432, dbname = "telemetry_db", driver = "RPostgreSQL" # or "RPostgres" ) telemetry <- Telemetry$new( app_name = "ProductionApp", data_storage = data_storage ) # Insert test data session <- shiny::MockShinySession$new() class(session) <- c(class(session), "ShinySession") data_storage$insert("ProductionApp", "login", session$token, list(username = "user123")) data_storage$insert("ProductionApp", "input", session$token, list(id = "filter", value = "active")) # Read event data events <- data_storage$read_event_data( date_from = Sys.Date() - 7, date_to = Sys.Date(), app_name = "ProductionApp" ) print(events) # Close connection when done data_storage$close() ``` -------------------------------- ### Configure Shiny Telemetry for Full Session Tracking Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Configures a Shiny application to start a telemetry session with comprehensive tracking enabled. This includes tracking all input changes, their values, login/logout events, browser information, navigation, and errors. It uses the `shiny.telemetry` library and a `Telemetry` object to manage the session. ```r library(shiny) library(shiny.telemetry) aulemetry <- Telemetry$new(app_name = "AnalyticsApp") shinyApp( ui = fluidPage( use_telemetry(), tabsetPanel( id = "main_tabs", tabPanel("Home", numericInput("value", "Value", 10)), tabPanel("Settings", textInput("username", "Username")) ), actionButton("save", "Save") ), server = function(input, output, session) { # Start session with full configuration telemetry$start_session( track_inputs = TRUE, # Track all input changes track_values = TRUE, # Store actual values login = TRUE, # Log session start logout = TRUE, # Log session end browser_version = TRUE, # Track browser info navigation_input_id = "main_tabs", # Track tab navigation username = NULL, # Auto-detect username track_anonymous_user = TRUE, # Use cookies for anonymous users track_errors = TRUE # Automatically log errors ) # App logic observeEvent(input$save, { # Your save logic }) } ) ``` -------------------------------- ### Accessing Telemetry Data from SQLite Database Source: https://github.com/appsilon/shiny.telemetry/blob/main/README.md Retrieves event data logged by shiny.telemetry within a specified date range. This example assumes the default SQLite data storage provider and path have been used. ```r # After running the instrumented app shiny.telemetry::Telemetry$new()$data_storage$read_event_data("2020-01-01", "2050-01-01") # Default provider and path for Telemetry$new() shiny.telemetry::DataStorageSQLite$new(db_path = "telemetry.sqlite")$read_event_data("2020-01-01", "2050-01-01") ``` -------------------------------- ### Use Log File Storage Backend for Telemetry in R Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Implements a simple JSON log file storage backend for the shiny.telemetry package. This method is suitable for lightweight deployments where a dedicated database is not required. The code snippet indicates the setup for this storage type. Requires the 'shiny.telemetry' library. ```r library(shiny.telemetry) ``` -------------------------------- ### Enable Debug Logging for Shiny Telemetry in R Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Activates detailed DEBUG level logging for the 'shiny.telemetry' namespace using the 'logger' package for troubleshooting. This example also shows integration within a basic Shiny application and how to add it to .Rprofile for persistence. Requires 'shiny.telemetry' and 'logger' packages. ```r library(shiny.telemetry) library(logger) # Enable DEBUG level logging for shiny.telemetry logger::log_threshold("DEBUG", namespace = "shiny.telemetry") # Now telemetry operations will produce detailed logs telemetry <- Telemetry$new() # Example of expected log output: # DEBUG [timestamp] path to db: telemetry.sqlite # DEBUG [timestamp] Writing 'input' event with id: 'my_input' # DEBUG [timestamp] event: login # Use in Shiny app library(shiny) shinyApp( ui = fluidPage( use_telemetry(), numericInput("n", "n", 1) ), server = function(input, output, session) { telemetry$start_session() # All telemetry calls will now be logged } ) # Add to .Rprofile for persistent debugging # logger::log_threshold("DEBUG", namespace = "shiny.telemetry") ``` -------------------------------- ### Setup Plumber REST API Backend for Telemetry in R Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Configures shiny.telemetry to use a remote Plumber API as its backend storage. This is useful for distributed applications. The snippet shows how to connect to both remote and local Plumber APIs, including setting authentication headers and testing the connection by inserting and reading data. Requires the 'shiny.telemetry' library. ```r library(shiny.telemetry) # Connect to Plumber API backend data_storage <- DataStoragePlumber$new( hostname = "api.example.com", port = 443, protocol = "https", path = "telemetry", secret = Sys.getenv("PLUMBER_SECRET"), authorization = Sys.getenv("CONNECT_AUTHORIZATION_KEY") ) telemetry <- Telemetry$new( app_name = "DistributedApp", data_storage = data_storage ) # Local Plumber API (development) data_storage_local <- DataStoragePlumber$new( hostname = "127.0.0.1", port = 8087, protocol = "http", path = NULL, secret = "my_shared_secret" ) # Test the connection session <- shiny::MockShinySession$new() class(session) <- c(class(session), "ShinySession") data_storage_local$insert("test", "event", session$token) events <- data_storage_local$read_event_data("2020-01-01", "2030-01-01") print(events) ``` -------------------------------- ### Set Logger Threshold for Debugging Telemetry (R) Source: https://github.com/appsilon/shiny.telemetry/blob/main/README.md This R code snippet sets the logging threshold for the 'shiny.telemetry' namespace to 'DEBUG' level. This is useful for debugging telemetry calls in a Shiny application. It requires the 'logger' package to be installed. The output will be detailed log messages from the telemetry namespace. ```r logger::log_threshold("DEBUG", namespace = "shiny.telemetry") ``` -------------------------------- ### Initialize Shiny Telemetry with File Backend Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Initializes the Telemetry system using a log file for data storage. It demonstrates manual logging of application events like user login, input changes, and navigation. The data can then be read from the log file, either all events or within a specific date range. ```r log_file_path <- "telemetry_log.txt" data_storage <- DataStorageLogFile$new(log_file_path = log_file_path) telemetry <- Telemetry$new( app_name = "SimpleApp", data_storage = data_storage ) # Manual logging session <- shiny::MockShinySession$new() class(session) <- c(class(session), "ShinySession") data_storage$insert("SimpleApp", "login", session$token, list(username = "alice")) data_storage$insert("SimpleApp", "input", session$token, list(id = "slider", value = 50)) data_storage$insert("SimpleApp", "navigation", session$token, list(id = "tab", value = "dashboard")) # Read all data events <- data_storage$read_event_data() print(events) # Read data from specific date range recent_events <- data_storage$read_event_data( date_from = Sys.Date() - 1, date_to = Sys.Date() ) print(recent_events) ``` -------------------------------- ### Create shiny_telemetry Database using sqlcmd Source: https://github.com/appsilon/shiny.telemetry/blob/main/inst/examples/mssql/README.md SQL command to create the 'shiny_telemetry' database using the sqlcmd utility. This is a prerequisite for the application to function correctly. Ensure the MS SQL Server instance is running before executing this command. ```sql CREATE DATABASE shiny_telemetry GO ``` -------------------------------- ### Direct DataStorage Access and Analysis with R Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Demonstrates direct access to SQLite data storage, reading event data, and performing analysis using dplyr for input events, navigation events, and session duration. Requires the 'shiny.telemetry' and 'dplyr' packages. ```r library(shiny.telemetry) library(dplyr) # Direct access to DataStorage data_storage <- DataStorageSQLite$new(db_path = "telemetry.sqlite") events <- data_storage$read_event_data("2020-01-01", "2050-01-01") # Analyze the data events %>% filter(type == "input") %>% group_by(id) %>% summarize( changes = n(), unique_sessions = n_distinct(session) ) %>% arrange(desc(changes)) # Navigation analysis events %>% filter(type == "navigation") %>% group_by(value) %>% summarize(visits = n()) %>% arrange(desc(visits)) # Session duration analysis events %>% group_by(session) %>% summarize( start = min(time), end = max(time), duration_minutes = as.numeric(difftime(max(time), min(time), units = "mins")) ) ``` -------------------------------- ### Initialize and Use shiny.telemetry DataStoragePlumber Source: https://github.com/appsilon/shiny.telemetry/blob/main/plumber_rest_api/README.md Demonstrates how to initialize the `DataStoragePlumber` class from the `shiny.telemetry` package and log various events. It connects to a local Plumber instance, logs a login and clicks, and then reads event data within a specified date range. ```R library(shiny.telemetry) data_storage <- DataStoragePlumber$new( username = "test_user", hostname = "127.0.0.1", port = 8087, protocol = "http" ) log_login(data_storage) log_click(data_storage, "an_id") log_click(data_storage, "a_different_id") data_storage$read_event_data("2020-01-01", "2035-01-01") ``` -------------------------------- ### Log User Navigation Events in Shiny Telemetry Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Demonstrates how to log user navigation events within a Shiny application using the `shiny.telemetry` package. It covers both automatic tracking of navigation elements (like tabsets) via `start_session` and manual logging of navigation actions using `log_navigation` and `log_navigation_manual`. ```r library(shiny) library(shiny.telemetry) aulemetry <- Telemetry$new() shinyApp( ui = fluidPage( use_telemetry(), tabsetPanel( id = "tabs", tabPanel("Dashboard", value = "dash"), tabPanel("Reports", value = "reports"), tabPanel("Settings", value = "settings") ) ), server = function(input, output, session) { # Automatic navigation tracking telemetry$start_session( navigation_input_id = "tabs" ) # Or manual navigation tracking telemetry$log_navigation("tabs") # Manual navigation events observeEvent(input$custom_nav, { telemetry$log_navigation_manual( navigation_id = "custom_section", value = "detailed_view" ) }) } ) ``` -------------------------------- ### Initialize Telemetry with Default SQLite Storage in R Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Initializes the shiny.telemetry package with a default SQLite database. It can be configured with a custom database path and integrated into a Shiny application to track user sessions and input changes. Requires the 'shiny' library for Shiny app functionality. ```r library(shiny.telemetry) # Initialize with default SQLite storage telemetry <- Telemetry$new() # Or specify custom SQLite database path db_path <- "custom_telemetry.sqlite" telemetry <- Telemetry$new( app_name = "MyDashboard", data_storage = DataStorageSQLite$new(db_path = db_path) ) # Use in a Shiny app library(shiny) shinyApp( ui = fluidPage( use_telemetry(), numericInput("n", "Number of points", 100), plotOutput("plot") ), server = function(input, output, session) { telemetry$start_session() output$plot <- renderPlot({ hist(runif(input$n)) }) } ) ``` -------------------------------- ### Generate additional dependencies for roxygenize hook Source: https://github.com/appsilon/shiny.telemetry/blob/main/CONTRIBUTING.md Generates a list of additional package dependencies required for the `roxygenize` hook when package dependencies are modified. This ensures the linter has the correct context. ```r precommit::snippet_generate("additional-deps-roxygenize") ``` -------------------------------- ### Log Login and Logout Events in Shiny Telemetry (R) Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Tracks user session lifecycle with authentication information. It supports both automatic detection of login/logout events within a Shiny app and manual logging. Requires 'shiny' and 'shiny.telemetry' libraries. The `start_session` function can be configured to automatically track these events. ```r library(shiny) library(shiny.telemetry) telemetry <- Telemetry$new() # Manual login tracking session <- shiny::MockShinySession$new() class(session) <- c(class(session), "ShinySession") telemetry$log_login(username = "alice", session = session) telemetry$log_logout(username = "alice", session = session) # Automatic in Shiny app shinyApp( ui = fluidPage( use_telemetry(), textOutput("welcome") ), server = function(input, output, session) { # Automatic login/logout tracking telemetry$start_session( login = TRUE, logout = TRUE, username = NULL # Auto-detect from session$user or environment ) # Or with custom username telemetry$start_session( username = "custom_user_123" ) # Manual tracking with specific username telemetry$log_login(username = session$user, session = session) output$welcome <- renderText({ paste("Welcome,", session$user) }) } ) ``` -------------------------------- ### Log Click Events in Shiny Telemetry (R) Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Tracks button clicks and user interactions for behavior analysis. This function simplifies the process of monitoring user engagement with UI elements. It requires the 'shiny' and 'shiny.telemetry' libraries and takes an event identifier string. ```r library(shiny) library(shiny.telemetry) telemetry <- Telemetry$new() shinyApp( ui = fluidPage( use_telemetry(), actionButton("save", "Save"), actionButton("cancel", "Cancel"), actionButton("delete", "Delete") ), server = function(input, output, session) { telemetry$start_session() # Log button clicks observeEvent(input$save, { telemetry$log_click("save_button") # Your save logic }) observeEvent(input$cancel, { telemetry$log_click("cancel_button") }) observeEvent(input$delete, { telemetry$log_click("delete_button") # Log with context telemetry$log_custom_event( "deletion", list(id = "delete_button", item_count = 5) ) }) } ) ``` -------------------------------- ### Configure Shiny Telemetry to Track Specific Inputs Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Configures a Shiny application to selectively track only specified input elements. This is achieved by disabling automatic input tracking and then explicitly logging desired inputs using `telemetry$log_input()`. This method helps reduce data volume and focus on critical user interactions. ```r library(shiny) library(shiny.telemetry) aulemetry <- Telemetry$new() shinyApp( ui = fluidPage( use_telemetry(), textInput("important", "Important Field"), numericInput("critical", "Critical Value", 0), textInput("ignored", "This Won't Be Tracked"), sliderInput("also_ignored", "Also Ignored", 0, 100, 50) ), server = function(input, output, session) { # Disable automatic input tracking telemetry$start_session(track_inputs = FALSE) # Track only specific inputs telemetry$log_input( input_id = c("important", "critical"), track_value = TRUE ) # Or track single input telemetry$log_input("important", track_value = TRUE) } ) ``` -------------------------------- ### Log Custom Events in Shiny Telemetry (R) Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Records custom application events with arbitrary data structures. This function is useful for tracking specific user actions or application states. It requires the 'shiny' and 'shiny.telemetry' libraries and accepts event type, details (as a list), and an optional session object. ```r library(shiny) library(shiny.telemetry) telemetry <- Telemetry$new() # Create mock session for testing session <- shiny::MockShinySession$new() class(session) <- c(class(session), "ShinySession") # Log custom events with different data structures telemetry$log_custom_event( event_type = "data_export", details = list(format = "csv", rows = 1500, filesize_mb = 2.3), session = session ) telemetry$log_custom_event( event_type = "filter_applied", details = list( filter_type = "date_range", start_date = "2024-01-01", end_date = "2024-12-31", affected_rows = 5000 ), session = session ) telemetry$log_custom_event( event_type = "api_call", details = list( endpoint = "/api/v2/data", status_code = 200, response_time_ms = 234 ), session = session ) # Use in Shiny app shinyApp( ui = fluidPage( use_telemetry(), actionButton("export", "Export Data") ), server = function(input, output, session) { telemetry$start_session() observeEvent(input$export, { # Your export logic result <- export_data() # Log the export event telemetry$log_custom_event( "data_export", list( format = result$format, records = result$count, timestamp = Sys.time() ) ) }) } ) ``` -------------------------------- ### Read Telemetry Data in Shiny Telemetry (R) Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Retrieves stored telemetry events for analysis and reporting. This functionality allows users to access historical data stored by the telemetry system. It requires the 'shiny.telemetry' and 'dplyr' libraries and provides methods to read all events or filter by date range and application name. ```r library(shiny.telemetry) library(dplyr) # Using Telemetry object telemetry <- Telemetry$new() # Read all events all_events <- telemetry$data_storage$read_event_data() print(all_events) # Read events from date range recent_events <- telemetry$data_storage$read_event_data( date_from = "2024-01-01", date_to = "2024-12-31" ) # Filter by app name app_events <- telemetry$data_storage$read_event_data( date_from = Sys.Date() - 30, date_to = Sys.Date(), app_name = "MyDashboard" ) ``` -------------------------------- ### Exclude Inputs from Shiny Telemetry Tracking using Regex Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Configures a Shiny application to track most inputs while excluding specific ones using regular expressions or exact IDs. This provides fine-grained control over which inputs are monitored, allowing for the exclusion of non-essential or problematic inputs like those from the DT package. ```r library(shiny) library(shiny.telemetry) aulemetry <- Telemetry$new() shinyApp( ui = fluidPage( use_telemetry(), # DT package inputs (excluded) DTOutput("dt_table"), # Regular inputs (tracked) textInput("search", "Search"), selectInput("filter", "Filter", choices = c("All", "Active", "Inactive")) ), server = function(input, output, session) { # Disable default tracking telemetry$start_session(track_inputs = FALSE) # Track all inputs except those matching regex pattern telemetry$log_all_inputs( track_values = TRUE, excluded_inputs_regex = "dt_[a-zA-Z0-9_]*$" # Exclude DT inputs ) # Or exclude by exact input IDs telemetry$log_all_inputs( excluded_inputs = c("dt_rows_selected", "dt_cell_clicked") ) # Force include specific inputs despite exclusion patterns telemetry$log_all_inputs( excluded_inputs_regex = "ns2-.*", include_input_ids = c("ns2-important_field") # Higher priority ) } ) ``` -------------------------------- ### Log Errors Automatically in Shiny Telemetry (R) Source: https://context7.com/appsilon/shiny.telemetry/llms.txt Captures and logs application errors for debugging and monitoring. This feature enables automatic error tracking for render functions and other reactive expressions. Requires 'shiny' and 'shiny.telemetry' libraries, and Shiny version 1.8.1 or later for full support. Manual error logging via `log_error` is also supported. ```r library(shiny) library(shiny.telemetry) telemetry <- Telemetry$new() shinyApp( ui = fluidPage( use_telemetry(), numericInput("divisor", "Divisor", 1), textOutput("result"), plotOutput("plot") ), server = function(input, output, session) { # Automatic error tracking (requires Shiny >= 1.8.1 for full support) telemetry$start_session(track_errors = TRUE) output$result <- renderText({ # This error will be automatically logged 100 / input$divisor }) output$plot <- renderPlot({ # This error will also be logged if (input$divisor < 0) { stop("Divisor cannot be negative") } plot(1:10) }) # Manual error logging observe({ tryCatch({ risky_operation() }, error = function(e) { telemetry$log_error( output_id = "custom_operation", message = conditionMessage(e) ) }) }) } ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.