From 696938c936b35df651ec26ca5a6202fed8b39f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mani=C3=A8re=20Louis?= Date: Wed, 14 Feb 2024 17:32:35 +0100 Subject: [PATCH] add tracking with input function trigger on observeEvent --- NAMESPACE | 3 +++ R/app_server.R | 8 ++++++++ R/fct_tracks.R | 20 ++++++++++++++++++++ R/mod_explore.R | 35 +++++++++++++++++++++++++++++++++-- man/tracks.Rd | 17 +++++++++++++++++ 5 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 R/fct_tracks.R create mode 100644 man/tracks.Rd diff --git a/NAMESPACE b/NAMESPACE index 58bf21d..6a5c7ab 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -50,6 +50,7 @@ export(run_app) export(sld_get_quantile_colors) export(sld_get_quantile_metric) export(sld_get_style) +export(tracks) export(utile_get_metric_name_value) export(utile_get_metric_type) export(utile_normalize_string) @@ -133,6 +134,8 @@ importFrom(shinycssloaders,withSpinner) importFrom(shinyjs,onclick) importFrom(shinyjs,runjs) importFrom(shinyjs,useShinyjs) +importFrom(shinylogs,store_null) +importFrom(shinylogs,track_usage) importFrom(stats,setNames) importFrom(utils,head) importFrom(utils,tail) diff --git a/R/app_server.R b/R/app_server.R index 343b3fa..2f47318 100644 --- a/R/app_server.R +++ b/R/app_server.R @@ -4,10 +4,18 @@ #' DO NOT REMOVE. #' @import shiny #' @importFrom DBI dbDisconnect +#' @importFrom shinylogs track_usage store_null #' #' @noRd app_server <- function(input, output, session) { + shinylogs::track_usage(storage_mode = shinylogs::store_null(), + what = "session") + + # observe({ + # tracks(input = input) + # }) + # set database connection con <- db_con() diff --git a/R/fct_tracks.R b/R/fct_tracks.R new file mode 100644 index 0000000..cb15d1e --- /dev/null +++ b/R/fct_tracks.R @@ -0,0 +1,20 @@ +#' Track input user session. +#' +#' @param input reactivesValues Shiny input. +#' +#' @return message with the list avec the input values tracked. +#' @export +tracks <- function(input = input){ + inputs_tracked <- c("exploremap_shape_click", "strahler", "metricfilter", "metric_type", + "metric", "unit_area", "roe_profile", "profile_metric_type", + "profile_metric", "profile_unit_area", "roe_profile", + "remove_profile_axe") + + values <- list() + for (name in names(input)) { + if (grepl(paste(inputs_tracked, collapse = "|"), name)) { + values[[name]] <- input[[name]] + } + } + return(message(list(values))) +} diff --git a/R/mod_explore.R b/R/mod_explore.R index ba6dbf9..62e0725 100644 --- a/R/mod_explore.R +++ b/R/mod_explore.R @@ -365,7 +365,8 @@ mod_explore_server <- function(id, con){ observeEvent(input$exploremap_shape_click,{ - shinylogs::track_usage(storage_mode = shinylogs::store_null(console = TRUE)) + # track input + tracks(input = input) #### bassin clicked #### if (input$exploremap_shape_click$group == params_map_group()[["bassin"]]){ @@ -556,6 +557,9 @@ mod_explore_server <- function(id, con){ observeEvent(input$metric_type, { + # track input + tracks(input = input) + if (!is.null(input$metric_type)){ update_popover("popover_metric_type", HTML(params_metrics_choice()[[input$metric_type]]$metric_type_info)) @@ -584,6 +588,10 @@ mod_explore_server <- function(id, con){ #### metric select #### observeEvent(c(input$metric, input$unit_area), ignoreInit = TRUE, { + + # track input + tracks(input = input) + # change field if unit_area in percentage if (!is.null(input$metric) && input$unit_area == "percent" && (input$metric_type %in% c("landuse", "continuity"))){ @@ -633,9 +641,13 @@ mod_explore_server <- function(id, con){ ### EVENT METRIC & AXIS RESULTS #### observeEvent(c(r_val$selected_metric, r_val$axis_click), { + if (r_val$profile_display == FALSE){ + + # track input + tracks(input = input) + if (!is.null(r_val$selected_metric) && !is.null(r_val$axis_click)){ - browser() r_val$profile_display = TRUE # this event run only one time controlled with profile_display @@ -668,6 +680,9 @@ mod_explore_server <- function(id, con){ observeEvent(input$profile_metric_type, { + # track input + tracks(input = input) + # build profile metric radio button r_val$ui_profile_metric = radioButtons( inputId = ns("profile_metric"), @@ -699,6 +714,10 @@ mod_explore_server <- function(id, con){ #### profile metric select #### observeEvent(c(input$profile_metric, input$profile_unit_area), ignoreInit = TRUE, { + + # track input + tracks(input = input) + # change field if unit_area in percentage if (!is.null(input$profile_metric) && input$profile_unit_area == "percent" && (input$profile_metric_type %in% c("landuse", "continuity"))){ @@ -732,6 +751,10 @@ mod_explore_server <- function(id, con){ #### profile metric remove axe #### observeEvent(input$remove_profile_axe, { + + # track input + tracks(input = input) + plotlyProxy("long_profile") %>% plotlyProxyInvoke("deleteTraces", 1) @@ -748,6 +771,10 @@ mod_explore_server <- function(id, con){ #### profile metric add ROE #### observeEvent(input$roe_profile, { + + # track input + tracks(input = input) + if (input$roe_profile == TRUE){ if (!is.null(r_val$roe_vertical_line)){ # remove the previous ROE vertical lines if exist @@ -773,6 +800,10 @@ mod_explore_server <- function(id, con){ ### EVENT FILTER #### observeEvent(c(input$strahler, input$metricfilter, r_val$ui_strahler_filter), { + + # track input + tracks(input = input) + if (is.null(input$metricfilter)){ # build WMS cql_filter r_val$cql_filter = paste0("gid_region=", r_val$selected_region_feature[["gid"]], diff --git a/man/tracks.Rd b/man/tracks.Rd new file mode 100644 index 0000000..31f664a --- /dev/null +++ b/man/tracks.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fct_tracks.R +\name{tracks} +\alias{tracks} +\title{Track input user session.} +\usage{ +tracks(input = input) +} +\arguments{ +\item{input}{reactivesValues Shiny input.} +} +\value{ +message with the list avec the input values tracked. +} +\description{ +Track input user session. +}