Skip to content

Commit 6bb26f5

Browse files
committed
regression with validate
1 parent f014f3e commit 6bb26f5

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

R/tm_a_regression.R

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,24 @@
3636
#'
3737
#' It takes the form of `c(value, min, max)` and it is passed to the `value_min_max`
3838
#' argument in `teal.widgets::optionalSliderInputValMinMax`.
39+
#' @param decorator (`teal_transform_module`, `language`, `function`)
3940
#'
4041
#' @templateVar ggnames `r regression_names`
4142
#' @template ggplot2_args_multi
4243
#'
4344
#' @inherit shared_params return
4445
#'
46+
#' @section Decorating module's output:
47+
#' Outputs produced by the module can be modified for any application. To do so, one needs to provide
48+
#' [teal_transform_module()] with `server` modifying outputed object in `data` (`teal_data`). Each
49+
#' module might have a different output object name and it's type, so there is no standard code to achieve this.
50+
#' However, `teal` provides couple wrappers which can simplify the process of decorating module's outputs:
51+
#' - `decorator` as a `language`: provide a simple expression to modify object of interests. For example
52+
#' `g <- g + ggtitle("Custom Title")`. Provided expression must be a working expression within module internals.
53+
#' - `decorator` as a `function`: provide a function which will take the output object and modify it in desired way.
54+
#' When function is provided object names don't need to match module's internal naming. For example
55+
#' `function(x) x <- x + ggtitle("Custom Title")`.
56+
#'
4557
#' @examples
4658
#' # general data example
4759
#' library(teal.widgets)
@@ -157,7 +169,7 @@ tm_a_regression <- function(label = "Regression Analysis",
157169
if (inherits(regressor, "data_extract_spec")) regressor <- list(regressor)
158170
if (inherits(response, "data_extract_spec")) response <- list(response)
159171
if (inherits(ggplot2_args, "ggplot2_args")) ggplot2_args <- list(default = ggplot2_args)
160-
decorate_objs <- lapply(decorator, FUN = decorate_teal_data, output_name = "plot")
172+
decorate_objs <- lapply(decorator, FUN = decorate_teal_data, output_name = "g")
161173

162174
# Start of assertions
163175
checkmate::assert_string(label)
@@ -253,7 +265,6 @@ ui_a_regression <- function(id, decorate_objs, ...) {
253265
ns <- NS(id)
254266
args <- list(...)
255267
is_single_dataset_value <- teal.transform::is_single_dataset(args$regressor, args$response)
256-
257268
teal.widgets::standard_layout(
258269
output = teal.widgets::white_small_well(tags$div(
259270
teal.widgets::plot_with_settings_ui(id = ns("myplot")),
@@ -285,13 +296,13 @@ ui_a_regression <- function(id, decorate_objs, ...) {
285296
),
286297
div(
287298
# todo: conditionalPanel based on the values of input$plot_type (we don't want to show inputs for hidden plots)
288-
ui_teal_data(ns("d_0"), decorate_objs[[1]]),
289-
ui_teal_data(ns("d_1"), decorate_objs[[1]]),
290-
ui_teal_data(ns("d_2"), decorate_objs[[1]]),
291-
ui_teal_data(ns("d_3"), decorate_objs[[1]]),
292-
ui_teal_data(ns("d_4"), decorate_objs[[1]]),
293-
ui_teal_data(ns("d_5"), decorate_objs[[1]]),
294-
ui_teal_data(ns("d_6"), decorate_objs[[1]])
299+
ui_transform_data(ns("d_0"), transforms = decorate_objs[[1]]),
300+
ui_transform_data(ns("d_1"), transforms = decorate_objs[[1]]),
301+
ui_transform_data(ns("d_2"), transforms = decorate_objs[[1]]),
302+
ui_transform_data(ns("d_3"), transforms = decorate_objs[[1]]),
303+
ui_transform_data(ns("d_4"), transforms = decorate_objs[[1]]),
304+
ui_transform_data(ns("d_5"), transforms = decorate_objs[[1]]),
305+
ui_transform_data(ns("d_6"), transforms = decorate_objs[[1]])
295306
),
296307
checkboxInput(ns("show_outlier"), label = "Display outlier labels", value = TRUE),
297308
conditionalPanel(
@@ -968,13 +979,13 @@ srv_a_regression <- function(id,
968979
)
969980
})
970981

971-
decorated_output_0 <- srv_teal_data(id = "d_0", data = output_plot_0, data_module = decorate_objs[[1]], modules = module())
972-
decorated_output_1 <- srv_teal_data(id = "d_1", data = output_plot_1, data_module = decorate_objs[[1]], modules = module())
973-
decorated_output_2 <- srv_teal_data(id = "d_2", data = output_plot_2, data_module = decorate_objs[[1]], modules = module())
974-
decorated_output_3 <- srv_teal_data(id = "d_3", data = output_plot_3, data_module = decorate_objs[[1]], modules = module())
975-
decorated_output_4 <- srv_teal_data(id = "d_4", data = output_plot_4, data_module = decorate_objs[[1]], modules = module())
976-
decorated_output_5 <- srv_teal_data(id = "d_5", data = output_plot_5, data_module = decorate_objs[[1]], modules = module())
977-
decorated_output_6 <- srv_teal_data(id = "d_6", data = output_plot_6, data_module = decorate_objs[[1]], modules = module())
982+
decorated_output_0 <- srv_transform_data(id = "d_0", data = output_plot_0, transforms = decorate_objs[[1]])
983+
decorated_output_1 <- srv_transform_data(id = "d_1", data = output_plot_1, transforms = decorate_objs[[1]])
984+
decorated_output_2 <- srv_transform_data(id = "d_2", data = output_plot_2, transforms = decorate_objs[[1]])
985+
decorated_output_3 <- srv_transform_data(id = "d_3", data = output_plot_3, transforms = decorate_objs[[1]])
986+
decorated_output_4 <- srv_transform_data(id = "d_4", data = output_plot_4, transforms = decorate_objs[[1]])
987+
decorated_output_5 <- srv_transform_data(id = "d_5", data = output_plot_5, transforms = decorate_objs[[1]])
988+
decorated_output_6 <- srv_transform_data(id = "d_6", data = output_plot_6, transforms = decorate_objs[[1]])
978989

979990

980991
output_q <- reactive({

0 commit comments

Comments
 (0)