diff --git a/DESCRIPTION b/DESCRIPTION index 9b1523f..939605b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,6 +20,7 @@ Imports: grDevices, htmltools, httr, + jsonlite, leaflet, magrittr, plotly, diff --git a/NAMESPACE b/NAMESPACE index 608a90f..fec69b9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -50,7 +50,8 @@ export(run_app) export(sld_get_quantile_colors) export(sld_get_quantile_metric) export(sld_get_style) -export(tracks) +export(track_inputs) +export(track_session) export(utile_get_metric_name_value) export(utile_get_metric_type) export(utile_normalize_string) @@ -85,6 +86,7 @@ importFrom(htmltools,img) importFrom(htmltools,span) importFrom(htmltools,tags) importFrom(httr,modify_url) +importFrom(jsonlite,toJSON) importFrom(leaflet,WMSTileOptions) importFrom(leaflet,addCircleMarkers) importFrom(leaflet,addControl) diff --git a/R/app_server.R b/R/app_server.R index 6ca30c3..05811a8 100644 --- a/R/app_server.R +++ b/R/app_server.R @@ -5,15 +5,12 @@ #' @import shiny #' @importFrom DBI dbDisconnect #' +#' #' @noRd app_server <- function(input, output, session) { # track session - session_tracks <- list( - session_id = session$token, - session_time = format(Sys.time(), "%Y-%m-%d %H:%M:%OS3%z") - ) - message(list(session_tracks)) + track_session(session = session) # set database connection con <- db_con() diff --git a/R/fct_tracks.R b/R/fct_tracks.R index cb15d1e..4a9cd12 100644 --- a/R/fct_tracks.R +++ b/R/fct_tracks.R @@ -1,10 +1,12 @@ -#' Track input user session. +#' Track input user inputs. #' #' @param input reactivesValues Shiny input. #' -#' @return message with the list avec the input values tracked. +#' @importFrom jsonlite toJSON +#' +#' @return message with the inputs name and value as json format. #' @export -tracks <- function(input = input){ +track_inputs <- 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", @@ -16,5 +18,21 @@ tracks <- function(input = input){ values[[name]] <- input[[name]] } } - return(message(list(values))) + return(message(toJSON(list(values)))) +} + +#' Track input user session id and datetime. +#' +#' @param session reactivesValues Shiny input. +#' +#' @importFrom jsonlite toJSON +#' +#' @return message with the session info name and value as json format. +#' @export +track_session <- function(session = session){ + session_tracks <- list( + session_id = session$token, + session_time = format(Sys.time(), "%Y-%m-%d %H:%M:%OS3%z") + ) + message(toJSON(list(session_tracks))) } diff --git a/R/mod_explore.R b/R/mod_explore.R index 62e0725..6e30566 100644 --- a/R/mod_explore.R +++ b/R/mod_explore.R @@ -366,7 +366,7 @@ mod_explore_server <- function(id, con){ observeEvent(input$exploremap_shape_click,{ # track input - tracks(input = input) + track_inputs(input = input) #### bassin clicked #### if (input$exploremap_shape_click$group == params_map_group()[["bassin"]]){ @@ -558,7 +558,7 @@ mod_explore_server <- function(id, con){ observeEvent(input$metric_type, { # track input - tracks(input = input) + track_inputs(input = input) if (!is.null(input$metric_type)){ update_popover("popover_metric_type", @@ -590,7 +590,7 @@ mod_explore_server <- function(id, con){ observeEvent(c(input$metric, input$unit_area), ignoreInit = TRUE, { # track input - tracks(input = input) + track_inputs(input = input) # change field if unit_area in percentage if (!is.null(input$metric) && input$unit_area == "percent" @@ -645,7 +645,7 @@ mod_explore_server <- function(id, con){ if (r_val$profile_display == FALSE){ # track input - tracks(input = input) + track_inputs(input = input) if (!is.null(r_val$selected_metric) && !is.null(r_val$axis_click)){ @@ -681,7 +681,7 @@ mod_explore_server <- function(id, con){ observeEvent(input$profile_metric_type, { # track input - tracks(input = input) + track_inputs(input = input) # build profile metric radio button r_val$ui_profile_metric = radioButtons( @@ -716,7 +716,7 @@ mod_explore_server <- function(id, con){ observeEvent(c(input$profile_metric, input$profile_unit_area), ignoreInit = TRUE, { # track input - tracks(input = input) + track_inputs(input = input) # change field if unit_area in percentage if (!is.null(input$profile_metric) && input$profile_unit_area == "percent" @@ -753,7 +753,7 @@ mod_explore_server <- function(id, con){ observeEvent(input$remove_profile_axe, { # track input - tracks(input = input) + track_inputs(input = input) plotlyProxy("long_profile") %>% plotlyProxyInvoke("deleteTraces", 1) @@ -773,7 +773,7 @@ mod_explore_server <- function(id, con){ observeEvent(input$roe_profile, { # track input - tracks(input = input) + track_inputs(input = input) if (input$roe_profile == TRUE){ if (!is.null(r_val$roe_vertical_line)){ @@ -802,7 +802,7 @@ mod_explore_server <- function(id, con){ observeEvent(c(input$strahler, input$metricfilter, r_val$ui_strahler_filter), { # track input - tracks(input = input) + track_inputs(input = input) if (is.null(input$metricfilter)){ # build WMS cql_filter diff --git a/man/tracks.Rd b/man/track_inputs.Rd similarity index 50% rename from man/tracks.Rd rename to man/track_inputs.Rd index 31f664a..f6a19c0 100644 --- a/man/tracks.Rd +++ b/man/track_inputs.Rd @@ -1,17 +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.} +\name{track_inputs} +\alias{track_inputs} +\title{Track input user inputs.} \usage{ -tracks(input = input) +track_inputs(input = input) } \arguments{ \item{input}{reactivesValues Shiny input.} } \value{ -message with the list avec the input values tracked. +message with the inputs name and value as json format. } \description{ -Track input user session. +Track input user inputs. } diff --git a/man/track_session.Rd b/man/track_session.Rd new file mode 100644 index 0000000..96955b7 --- /dev/null +++ b/man/track_session.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fct_tracks.R +\name{track_session} +\alias{track_session} +\title{Track input user session id and datetime.} +\usage{ +track_session(session = session) +} +\arguments{ +\item{session}{reactivesValues Shiny input.} +} +\value{ +message with the session info name and value as json format. +} +\description{ +Track input user session id and datetime. +}