diff --git a/NAMESPACE b/NAMESPACE index fec69b9..01759ff 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,6 @@ # Generated by roxygen2: do not edit by hand export("%>%") -export(button_label_with_popover) export(cr_profile_empty) export(cr_section_main) export(data_get_axis) @@ -44,7 +43,6 @@ export(map_wms_metric) export(params_map_group) export(params_metrics_choice) export(params_unit_area) -export(params_url_remonterletemps) export(params_wms) export(run_app) export(sld_get_quantile_colors) @@ -52,9 +50,11 @@ export(sld_get_quantile_metric) export(sld_get_style) export(track_inputs) export(track_session) -export(utile_get_metric_name_value) -export(utile_get_metric_type) -export(utile_normalize_string) +export(utils_button_label_with_popover) +export(utils_get_metric_name_value) +export(utils_get_metric_type) +export(utils_normalize_string) +export(utils_url_remonterletemps) import(shiny) importFrom(DBI,SQL) importFrom(DBI,dbConnect) diff --git a/R/app_server.R b/R/app_server.R index 05811a8..e63f741 100644 --- a/R/app_server.R +++ b/R/app_server.R @@ -19,6 +19,7 @@ app_server <- function(input, output, session) { mod_explore_server("explore_1", con) mod_documentation_server("documentation_1") + # disconnect database when closing session onStop(function() { if (!is.null(con)) { DBI::dbDisconnect(con) diff --git a/R/fct_tracks.R b/R/fct_track.R similarity index 100% rename from R/fct_tracks.R rename to R/fct_track.R diff --git a/R/fct_utils.R b/R/fct_utils.R index 793c59a..57bf7b5 100644 --- a/R/fct_utils.R +++ b/R/fct_utils.R @@ -9,11 +9,11 @@ #' #' @examples #' original_string <- "Thïs is à sâmplè strîng with spèciál chàracters!" -#' normalized_string <- utile_normalize_string(original_string) +#' normalized_string <- utils_normalize_string(original_string) #' cat(normalized_string) # "thisisasamplestringwithspecialcharacters" #' #' @export -utile_normalize_string <- function(input_string) { +utils_normalize_string <- function(input_string) { # Remove accents and diacritics input_string <- chartr("ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÌÍÎÏìíîïÙÚÛÜùúûüÝýÑñÇç", "AAAAAAaaaaaaOOOOOOooooooEEEEeeeeIIIIiiiiUUUUuuuuYyNnCc", @@ -40,10 +40,10 @@ utile_normalize_string <- function(input_string) { #' @return A named character vector with metric type titles as names and metric type values as values. #' #' @examples -#' metric_types <- utile_get_metric_type(params_metrics_choice()) +#' metric_types <- utils_get_metric_type(params_metrics_choice()) #' #' @export -utile_get_metric_type <- function(input_list) { +utils_get_metric_type <- function(input_list) { metric_type <- setNames(names(sapply(input_list, function(x) x$metric_type_title)), sapply(input_list, function(x) x$metric_type_title)) return(metric_type) } @@ -57,10 +57,10 @@ utile_get_metric_type <- function(input_list) { #' @return A named character vector with all the metric names and values. #' #' @examples -#' metrics <- utile_get_metric_name_value("largeur") +#' metrics <- utils_get_metric_name_value("largeur") #' #' @export -utile_get_metric_name_value <- function(metric_type){ +utils_get_metric_name_value <- function(metric_type){ metric_name <- sapply(params_metrics_choice()[[metric_type]]$metric_type_value, function(x) x$metric_title) return(metric_name) } @@ -82,10 +82,10 @@ utile_get_metric_name_value <- function(metric_type){ #' metric type. #' #' @examples -#' metric_buttons <- button_label_with_popover("largeur") +#' metric_buttons <- utils_button_label_with_popover("largeur") #' #' @export -button_label_with_popover <- function(metric_type) { +utils_button_label_with_popover <- function(metric_type) { metrics <- names(params_metrics_choice()[[metric_type]]$metric_type_value) buttons <- list() @@ -133,8 +133,8 @@ button_label_with_popover <- function(metric_type) { #' @export #' #' @examples -#' params_url_remonterletemps(lng=6.869433, lat=45.923690, zoom = 12) -params_url_remonterletemps <- function(lng=6.869433, +#' utils_url_remonterletemps(lng=6.869433, lat=45.923690, zoom = 12) +utils_url_remonterletemps <- function(lng=6.869433, lat=45.923690, zoom = 12){ url <- glue::glue("https://remonterletemps.ign.fr/comparer/basic?x={lng}&y={lat}&z={zoom}&layer1=GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2&layer2=ORTHOIMAGERY.ORTHOPHOTOS&mode=vSlider") diff --git a/R/mod_explore.R b/R/mod_explore.R index 6e30566..66f2c7b 100644 --- a/R/mod_explore.R +++ b/R/mod_explore.R @@ -207,7 +207,7 @@ mod_explore_server <- function(id, con){ onclick(id = "logo_ign_remonterletemps", expr = runjs(sprintf("window.open('%s', '_blank')", - params_url_remonterletemps(lng = input$exploremap_center$lng, + utils_url_remonterletemps(lng = input$exploremap_center$lng, lat = input$exploremap_center$lat, zoom = input$exploremap_zoom))) ) @@ -406,7 +406,7 @@ mod_explore_server <- function(id, con){ r_val$selected_region_feature = data_get_region(region_click_id = r_val$region_click$id, con = con) # set region name to download - r_val$region_name = utile_normalize_string(r_val$selected_region_feature$lbregionhy) + r_val$region_name = utils_normalize_string(r_val$selected_region_feature$lbregionhy) # get the axis in the region r_val$network_region_axis = data_get_axis(selected_region_id = r_val$region_click$id, con = con) @@ -441,8 +441,8 @@ mod_explore_server <- function(id, con){ # build metric selectInput r_val$ui_metric_type = selectInput(ns("metric_type"), "Sélectionnez une métrique :", - choices = utile_get_metric_type(params_metrics_choice()), - selected = utile_get_metric_type(params_metrics_choice())[1]) + choices = utils_get_metric_type(params_metrics_choice()), + selected = utils_get_metric_type(params_metrics_choice())[1]) # create download button r_val$ui_download = downloadButton( @@ -570,8 +570,8 @@ mod_explore_server <- function(id, con){ r_val$ui_metric = radioButtons( inputId = ns("metric"), label = NULL, - choiceNames = button_label_with_popover(input$metric_type), - choiceValues = as.list(names(utile_get_metric_name_value(input$metric_type))), + choiceNames = utils_button_label_with_popover(input$metric_type), + choiceValues = as.list(names(utils_get_metric_name_value(input$metric_type))), selected = character(0) ) @@ -653,8 +653,8 @@ mod_explore_server <- function(id, con){ # build input for profile metric type r_val$ui_profile_metric_type = selectInput(ns("profile_metric_type"), "Ajoutez une métrique :", - choices = utile_get_metric_type(params_metrics_choice()), - selected = utile_get_metric_type(params_metrics_choice())[1]) + choices = utils_get_metric_type(params_metrics_choice()), + selected = utils_get_metric_type(params_metrics_choice())[1]) # built ROE checkboxInput and input r_val$ui_roe_profile = checkboxInput(ns("roe_profile"), label = "ROE", value = FALSE) @@ -687,8 +687,8 @@ mod_explore_server <- function(id, con){ r_val$ui_profile_metric = radioButtons( inputId = ns("profile_metric"), label = NULL, - choiceNames = unname(utile_get_metric_name_value(input$profile_metric_type)), - choiceValues = names(utile_get_metric_name_value(input$profile_metric_type)), + choiceNames = unname(utils_get_metric_name_value(input$profile_metric_type)), + choiceValues = names(utils_get_metric_name_value(input$profile_metric_type)), selected = character(0) ) diff --git a/man/track_inputs.Rd b/man/track_inputs.Rd index f6a19c0..40393a8 100644 --- a/man/track_inputs.Rd +++ b/man/track_inputs.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/fct_tracks.R +% Please edit documentation in R/fct_track.R \name{track_inputs} \alias{track_inputs} \title{Track input user inputs.} diff --git a/man/track_session.Rd b/man/track_session.Rd index 96955b7..a0825ea 100644 --- a/man/track_session.Rd +++ b/man/track_session.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/fct_tracks.R +% Please edit documentation in R/fct_track.R \name{track_session} \alias{track_session} \title{Track input user session id and datetime.} diff --git a/man/button_label_with_popover.Rd b/man/utils_button_label_with_popover.Rd similarity index 76% rename from man/button_label_with_popover.Rd rename to man/utils_button_label_with_popover.Rd index 55f7a36..d311e1b 100644 --- a/man/button_label_with_popover.Rd +++ b/man/utils_button_label_with_popover.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/fct_utils.R -\name{button_label_with_popover} -\alias{button_label_with_popover} +\name{utils_button_label_with_popover} +\alias{utils_button_label_with_popover} \title{Create buttons with popover for metric labels.} \usage{ -button_label_with_popover(metric_type) +utils_button_label_with_popover(metric_type) } \arguments{ \item{metric_type}{A character string specifying the metric type.} @@ -22,6 +22,6 @@ extract metric labels and corresponding popover information for the specified metric type. } \examples{ -metric_buttons <- button_label_with_popover("largeur") +metric_buttons <- utils_button_label_with_popover("largeur") } diff --git a/man/utile_get_metric_name_value.Rd b/man/utils_get_metric_name_value.Rd similarity index 73% rename from man/utile_get_metric_name_value.Rd rename to man/utils_get_metric_name_value.Rd index 0c6b080..03f4141 100644 --- a/man/utile_get_metric_name_value.Rd +++ b/man/utils_get_metric_name_value.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/fct_utils.R -\name{utile_get_metric_name_value} -\alias{utile_get_metric_name_value} +\name{utils_get_metric_name_value} +\alias{utils_get_metric_name_value} \title{Get a named vector of all the metric from the metric type from the params metric list.} \usage{ -utile_get_metric_name_value(metric_type) +utils_get_metric_name_value(metric_type) } \arguments{ \item{metric_type}{A character with metric type.} @@ -16,6 +16,6 @@ A named character vector with all the metric names and values. This function extracts metric names and value with metric type stored in params metric list. } \examples{ -metrics <- utile_get_metric_name_value("largeur") +metrics <- utils_get_metric_name_value("largeur") } diff --git a/man/utile_get_metric_type.Rd b/man/utils_get_metric_type.Rd similarity index 78% rename from man/utile_get_metric_type.Rd rename to man/utils_get_metric_type.Rd index 9e246a4..041a28c 100644 --- a/man/utile_get_metric_type.Rd +++ b/man/utils_get_metric_type.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/fct_utils.R -\name{utile_get_metric_type} -\alias{utile_get_metric_type} +\name{utils_get_metric_type} +\alias{utils_get_metric_type} \title{Get a named vector of metric types from the params metric list.} \usage{ -utile_get_metric_type(input_list) +utils_get_metric_type(input_list) } \arguments{ \item{input_list}{A list of objects where each object has a 'metric_type_title' field.} @@ -17,6 +17,6 @@ This function extracts metric types from a list of objects and returns a named vector with metric type titles as names and metric type values as values. } \examples{ -metric_types <- utile_get_metric_type(params_metrics_choice()) +metric_types <- utils_get_metric_type(params_metrics_choice()) } diff --git a/man/utile_normalize_string.Rd b/man/utils_normalize_string.Rd similarity index 81% rename from man/utile_normalize_string.Rd rename to man/utils_normalize_string.Rd index 224c911..3deaf37 100644 --- a/man/utile_normalize_string.Rd +++ b/man/utils_normalize_string.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/fct_utils.R -\name{utile_normalize_string} -\alias{utile_normalize_string} +\name{utils_normalize_string} +\alias{utils_normalize_string} \title{Normalize a string by removing spaces, accents, and special characters.} \usage{ -utile_normalize_string(input_string) +utils_normalize_string(input_string) } \arguments{ \item{input_string}{The input string to be normalized.} @@ -18,7 +18,7 @@ and special characters. It then converts the string to lowercase. } \examples{ original_string <- "Thïs is à sâmplè strîng with spèciál chàracters!" -normalized_string <- utile_normalize_string(original_string) +normalized_string <- utils_normalize_string(original_string) cat(normalized_string) # "thisisasamplestringwithspecialcharacters" } diff --git a/man/params_url_remonterletemps.Rd b/man/utils_url_remonterletemps.Rd similarity index 65% rename from man/params_url_remonterletemps.Rd rename to man/utils_url_remonterletemps.Rd index 1e78263..aada0a4 100644 --- a/man/params_url_remonterletemps.Rd +++ b/man/utils_url_remonterletemps.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/fct_utils.R -\name{params_url_remonterletemps} -\alias{params_url_remonterletemps} +\name{utils_url_remonterletemps} +\alias{utils_url_remonterletemps} \title{get IGN remonterletemps url.} \usage{ -params_url_remonterletemps(lng = 6.869433, lat = 45.92369, zoom = 12) +utils_url_remonterletemps(lng = 6.869433, lat = 45.92369, zoom = 12) } \arguments{ \item{lng}{longitude.} @@ -20,5 +20,5 @@ a string with url link. This function take longitude and latitude to build and url to go IGN remonterletemps website on the same place. } \examples{ -params_url_remonterletemps(lng=6.869433, lat=45.923690, zoom = 12) +utils_url_remonterletemps(lng=6.869433, lat=45.923690, zoom = 12) } diff --git a/tests/testthat/test-fct_utils.R b/tests/testthat/test-fct_utils.R index 1f2d36f..4859cb8 100644 --- a/tests/testthat/test-fct_utils.R +++ b/tests/testthat/test-fct_utils.R @@ -1,11 +1,11 @@ -test_that("params_url_remonterletemps works", { - url <- params_url_remonterletemps(lng=6.869433, lat=45.923690, zoom = 12) +test_that("utils_url_remonterletemps works", { + url <- utils_url_remonterletemps(lng=6.869433, lat=45.923690, zoom = 12) expect_true(inherits(url, "character"), "character url loaded") }) -test_that("utile_normalize_string works", { +test_that("utils_normalize_string works", { original_string <- "Thïs is à sâmplè strîng with spèciál chàracters!" - normalized_string <- utile_normalize_string(original_string) + normalized_string <- utils_normalize_string(original_string) expect_true(normalized_string == "thisisasamplestringwithspecialcharacters") })