From 59f9de019ae916001be4c97169fad4663ad4083c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Thu, 21 Mar 2024 12:01:44 +0100 Subject: [PATCH] feat: adds extra parameters to methods that use it --- R/TealAppDriver.R | 39 ++++++++++++++++++++++++++++++--------- man/TealAppDriver.Rd | 12 ++++++++---- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/R/TealAppDriver.R b/R/TealAppDriver.R index 986a2073a8..1f92416913 100644 --- a/R/TealAppDriver.R +++ b/R/TealAppDriver.R @@ -194,14 +194,16 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. #' #' @param input_id (character) The shiny input id to get the value from. #' @param value The value to set the input to. + #' @param ... Additional arguments to be passed to `shinytest2::AppDriver$set_inputs` #' #' @return The `TealAppDriver` object invisibly. - set_module_input = function(input_id, value) { + set_module_input = function(input_id, value, ...) { checkmate::check_string(input_id) checkmate::check_string(value) self$set_input( sprintf("%s-%s", self$active_module_ns(), input_id), - value + value, + ... ) invisible(self) }, @@ -264,9 +266,10 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. #' #' @param dataset_name (character) The name of the dataset to add the filter variable to. #' @param var_name (character) The name of the variable to add to the filter panel. + #' @param ... Additional arguments to be passed to `shinytest2::AppDriver$set_inputs` #' #' @return The `TealAppDriver` object invisibly. - add_filter_var = function(dataset_name, var_name) { + add_filter_var = function(dataset_name, var_name, ...) { checkmate::check_string(dataset_name) checkmate::check_string(var_name) self$set_input( @@ -275,7 +278,8 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. self$active_filters_ns(), dataset_name ), - var_name + var_name, + ... ) invisible(self) }, @@ -322,10 +326,13 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. #' @param dataset_name (character) The name of the dataset to set the filter value for. #' @param var_name (character) The name of the variable to set the filter value for. #' @param input The value to set the filter to. - #' @param type (character) The type of the filter to get the value from. Default is `categorical`. + #' @param ... Additional arguments to be passed to `shinytest2::AppDriver$set_inputs` #' #' @return The `TealAppDriver` object invisibly. - set_active_filter_selection = function(dataset_name, var_name, input) { + set_active_filter_selection = function(dataset_name, + var_name, + input, + ...) { checkmate::check_string(dataset_name) checkmate::check_string(var_name) checkmate::check_string(input) @@ -365,16 +372,30 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. if (identical(slices_suffix, "selection_manual")) { checkmate::assert_numeric(input, len = 2) + extra_formals <- formals(app$set_inputs) + + checkmate::assert_choice(dots$priority_, formals(self$set_inputs)) + + dots <- rlang::list2(...) self$run_js( sprintf( - "Shiny.setInputValue('%s:sw.numericRange', [%f, %f], {priority: 'event'})", + "Shiny.setInputValue('%s:sw.numericRange', [%f, %f], {priority: '%s'})", slices_input_id, input[[1]], - input[[2]] + input[[2]], + priority_ = dplyr::coalesce(dots$priority_, "input", .size = 1) ) ) + self$wait_for_idle( + wait = dplyr::coalesce(dots$wait_, TRUE, .size = 1), + timeout = dplyr::coalesce(dots$timeout_, private$timeout, .size = 1) + ) } else if (identical(slices_suffix, "selection")) { - self$set_input(slices_input_id, input) + self$set_input( + slices_input_id, + input, + ... + ) } else { stop("Filter selection set not supported for this slice.") } diff --git a/man/TealAppDriver.Rd b/man/TealAppDriver.Rd index 355bc547d3..f714e0af44 100644 --- a/man/TealAppDriver.Rd +++ b/man/TealAppDriver.Rd @@ -320,7 +320,7 @@ The value of the shiny output. Set the input in the module in the \code{teal} app. This function will only set inputs in the name space of the current active teal module. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{TealAppDriver$set_module_input(input_id, value)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{TealAppDriver$set_module_input(input_id, value, ...)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -329,6 +329,8 @@ This function will only set inputs in the name space of the current active teal \item{\code{input_id}}{(character) The shiny input id to get the value from.} \item{\code{value}}{The value to set the input to.} + +\item{\code{...}}{Additional arguments to be passed to \code{shinytest2::AppDriver$set_inputs}} } \if{html}{\out{}} } @@ -370,7 +372,7 @@ If \code{NULL}, the filter variables for all the datasets will be returned in a \subsection{Method \code{add_filter_var()}}{ Add a new variable from the dataset to be filtered. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{TealAppDriver$add_filter_var(dataset_name, var_name)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{TealAppDriver$add_filter_var(dataset_name, var_name, ...)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -379,6 +381,8 @@ Add a new variable from the dataset to be filtered. \item{\code{dataset_name}}{(character) The name of the dataset to add the filter variable to.} \item{\code{var_name}}{(character) The name of the variable to add to the filter panel.} + +\item{\code{...}}{Additional arguments to be passed to \code{shinytest2::AppDriver$set_inputs}} } \if{html}{\out{}} } @@ -416,7 +420,7 @@ The \code{TealAppDriver} object invisibly. \subsection{Method \code{set_active_filter_selection()}}{ Set the active filter values for a variable of a dataset in the active filter variable panel. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{TealAppDriver$set_active_filter_selection(dataset_name, var_name, input)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{TealAppDriver$set_active_filter_selection(dataset_name, var_name, input, ...)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -428,7 +432,7 @@ Set the active filter values for a variable of a dataset in the active filter va \item{\code{input}}{The value to set the filter to.} -\item{\code{type}}{(character) The type of the filter to get the value from. Default is \code{categorical}.} +\item{\code{...}}{Additional arguments to be passed to \code{shinytest2::AppDriver$set_inputs}} } \if{html}{\out{}} }