From 780ab58a66b537432862246a72c52502610dd313 Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 23 Apr 2024 13:46:57 +0200 Subject: [PATCH 1/4] get_active_module_*ws_output --- R/TealAppDriver.R | 33 +++++++++++++++++++++++++++++++++ man/TealAppDriver.Rd | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/R/TealAppDriver.R b/R/TealAppDriver.R index 6ef0094071..5f9e514fe6 100644 --- a/R/TealAppDriver.R +++ b/R/TealAppDriver.R @@ -216,6 +216,39 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. self$get_value(output = sprintf("%s-%s", self$active_module_ns(), output_id)) }, #' @description + #' Get the output from the module's `teal.widgets::table_with_settings` in the `teal` app. + #' This function will only access outputs from the name space of the current active teal module. + #' + #' @param which (integer) If there is more than one table, which should be extracted. + #' + #' @return The data.frame with table contents. + get_active_module_tws_output = function(which = 1) { + checkmate::check_number(which, lower = 1) + table <- + rvest::html_table( + self$get_html_rvest( + self$active_module_element("table-table-with-settings") + ), + fill = TRUE + ) + if (identical(table, list())) { + table + } else { + table[[which]] + } + }, + #' @description + #' Get the output from the module's `teal.widgets::plot_with_settings` in the `teal` app. + #' This function will only access plots from the name space of the current active teal module. + #' + #' @return The `src` attribute as `character(1)` vector. + get_active_module_pws_output = function() { + self$get_attr( + self$active_module_element("myplot-plot_main > img"), + "src" + ) + }, + #' @description #' Set the input in the module in the `teal` app. #' This function will only set inputs in the name space of the current active teal module. #' diff --git a/man/TealAppDriver.Rd b/man/TealAppDriver.Rd index e4b098c09f..fa3efce44f 100644 --- a/man/TealAppDriver.Rd +++ b/man/TealAppDriver.Rd @@ -33,6 +33,8 @@ driving a teal application for performing interactions for \code{shinytest2} tes \item \href{#method-TealAppDriver-active_filters_ns}{\code{TealAppDriver$active_filters_ns()}} \item \href{#method-TealAppDriver-get_active_module_input}{\code{TealAppDriver$get_active_module_input()}} \item \href{#method-TealAppDriver-get_active_module_output}{\code{TealAppDriver$get_active_module_output()}} +\item \href{#method-TealAppDriver-get_active_module_tws_output}{\code{TealAppDriver$get_active_module_tws_output()}} +\item \href{#method-TealAppDriver-get_active_module_pws_output}{\code{TealAppDriver$get_active_module_pws_output()}} \item \href{#method-TealAppDriver-set_active_module_input}{\code{TealAppDriver$set_active_module_input()}} \item \href{#method-TealAppDriver-get_active_filter_vars}{\code{TealAppDriver$get_active_filter_vars()}} \item \href{#method-TealAppDriver-is_visible}{\code{TealAppDriver$is_visible()}} @@ -349,6 +351,41 @@ The value of the shiny output. } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-TealAppDriver-get_active_module_tws_output}{}}} +\subsection{Method \code{get_active_module_tws_output()}}{ +Get the output from the module's \code{teal.widgets::table_with_settings} in the \code{teal} app. +This function will only access outputs from the name space of the current active teal module. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{TealAppDriver$get_active_module_tws_output(which = 1)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{which}}{(integer) If there is more than one table, which should be extracted.} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +The data.frame with table contents. +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-TealAppDriver-get_active_module_pws_output}{}}} +\subsection{Method \code{get_active_module_pws_output()}}{ +Get the output from the module's \code{teal.widgets::plot_with_settings} in the \code{teal} app. +This function will only access plots from the name space of the current active teal module. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{TealAppDriver$get_active_module_pws_output()}\if{html}{\out{
}} +} + +\subsection{Returns}{ +The \code{src} attribute as \code{character(1)} vector. +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-TealAppDriver-set_active_module_input}{}}} \subsection{Method \code{set_active_module_input()}}{ From 0e70c9b275937c7f4e40639971fe8aca010fcfbd Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 24 Apr 2024 10:09:08 +0200 Subject: [PATCH 2/4] pass *ws namespace name as a parameter --- R/TealAppDriver.R | 13 +++++++++---- man/TealAppDriver.Rd | 13 +++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/R/TealAppDriver.R b/R/TealAppDriver.R index 5f9e514fe6..bf4652c2f1 100644 --- a/R/TealAppDriver.R +++ b/R/TealAppDriver.R @@ -219,15 +219,17 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. #' Get the output from the module's `teal.widgets::table_with_settings` in the `teal` app. #' This function will only access outputs from the name space of the current active teal module. #' + #' @param tws (`character(1)`) `table_with_settings` namespace name. #' @param which (integer) If there is more than one table, which should be extracted. #' #' @return The data.frame with table contents. - get_active_module_tws_output = function(which = 1) { + get_active_module_tws_output = function(tws, which = 1) { checkmate::check_number(which, lower = 1) + checkmate::check_string(tws) table <- rvest::html_table( self$get_html_rvest( - self$active_module_element("table-table-with-settings") + self$active_module_element(sprintf("%s-table-with-settings", tws)) ), fill = TRUE ) @@ -241,10 +243,13 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. #' Get the output from the module's `teal.widgets::plot_with_settings` in the `teal` app. #' This function will only access plots from the name space of the current active teal module. #' + #' @param pws (`character(1)`) `plot_with_settings` namespace name. + #' #' @return The `src` attribute as `character(1)` vector. - get_active_module_pws_output = function() { + get_active_module_pws_output = function(pws) { + checkmate::check_string(pws) self$get_attr( - self$active_module_element("myplot-plot_main > img"), + self$active_module_element(sprintf("%s-plot_main > img", pws)), "src" ) }, diff --git a/man/TealAppDriver.Rd b/man/TealAppDriver.Rd index fa3efce44f..787df54fc0 100644 --- a/man/TealAppDriver.Rd +++ b/man/TealAppDriver.Rd @@ -357,12 +357,14 @@ The value of the shiny output. Get the output from the module's \code{teal.widgets::table_with_settings} in the \code{teal} app. This function will only access outputs from the name space of the current active teal module. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{TealAppDriver$get_active_module_tws_output(which = 1)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{TealAppDriver$get_active_module_tws_output(tws, which = 1)}\if{html}{\out{
}} } \subsection{Arguments}{ \if{html}{\out{
}} \describe{ +\item{\code{tws}}{(\code{character(1)}) \code{table_with_settings} namespace name.} + \item{\code{which}}{(integer) If there is more than one table, which should be extracted.} } \if{html}{\out{
}} @@ -378,9 +380,16 @@ The data.frame with table contents. Get the output from the module's \code{teal.widgets::plot_with_settings} in the \code{teal} app. This function will only access plots from the name space of the current active teal module. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{TealAppDriver$get_active_module_pws_output()}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{TealAppDriver$get_active_module_pws_output(pws)}\if{html}{\out{
}} } +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{pws}}{(\code{character(1)}) \code{plot_with_settings} namespace name.} +} +\if{html}{\out{
}} +} \subsection{Returns}{ The \code{src} attribute as \code{character(1)} vector. } From 10b2a0dc30e0cb792478dff282ca0835e47ef893 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 24 Apr 2024 10:10:32 +0200 Subject: [PATCH 3/4] check table emptyness with length --- R/TealAppDriver.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/TealAppDriver.R b/R/TealAppDriver.R index d667d44e98..5a3cdd38bb 100644 --- a/R/TealAppDriver.R +++ b/R/TealAppDriver.R @@ -260,7 +260,7 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. ), fill = TRUE ) - if (identical(table, list())) { + if (length(table) == 0) { table } else { table[[which]] From da8c778f582794e2d9c8a42f5aeca45c7d80e5f0 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:17:14 +0200 Subject: [PATCH 4/4] Update R/TealAppDriver.R Co-authored-by: kartikeya kirar Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/TealAppDriver.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/TealAppDriver.R b/R/TealAppDriver.R index 5a3cdd38bb..1eee1eab8e 100644 --- a/R/TealAppDriver.R +++ b/R/TealAppDriver.R @@ -261,7 +261,7 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. fill = TRUE ) if (length(table) == 0) { - table + data.frame() } else { table[[which]] }