Skip to content

Commit

Permalink
factorize track session and track as json format
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisManiere committed Feb 15, 2024
1 parent c9175a4 commit ea4d0f1
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 25 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Imports:
grDevices,
htmltools,
httr,
jsonlite,
leaflet,
magrittr,
plotly,
Expand Down
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
26 changes: 22 additions & 4 deletions R/fct_tracks.R
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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)))
}
18 changes: 9 additions & 9 deletions R/mod_explore.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]){
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)){

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)){
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions man/tracks.Rd → man/track_inputs.Rd

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

17 changes: 17 additions & 0 deletions man/track_session.Rd

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

0 comments on commit ea4d0f1

Please sign in to comment.