Skip to content

Commit

Permalink
add tracking with input function trigger on observeEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisManiere committed Feb 14, 2024
1 parent 5c3d897 commit 696938c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
8 changes: 8 additions & 0 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
20 changes: 20 additions & 0 deletions R/fct_tracks.R
Original file line number Diff line number Diff line change
@@ -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)))
}
35 changes: 33 additions & 2 deletions R/mod_explore.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]){
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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"))){
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"))){
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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"]],
Expand Down
17 changes: 17 additions & 0 deletions man/tracks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 696938c

Please sign in to comment.