Skip to content
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions R/tm_g_bivariate.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
#'
#' @inherit shared_params return
#'
#' @section Decorating `tm_outliers`:
#'
#' This module creates below objects that can be modified with decorators:
#' - `plot` (`ggplot2`)
#'
#' For additional details and examples of decorators, refer to the vignette
#' `vignette("decorate-modules-output", package = "teal")` or the [`teal_transform_module()`] documentation.
#'
#'
#' @examplesShinylive
#' library(teal.modules.general)
#' interactive <- function() TRUE
Expand Down Expand Up @@ -185,7 +194,8 @@ tm_g_bivariate <- function(label = "Bivariate Plots",
ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
ggplot2_args = teal.widgets::ggplot2_args(),
pre_output = NULL,
post_output = NULL) {
post_output = NULL,
decorators = list(default = teal_transform_module())) {
message("Initializing tm_g_bivariate")

# Normalize the parameters
Expand Down Expand Up @@ -265,6 +275,8 @@ tm_g_bivariate <- function(label = "Bivariate Plots",

checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)

checkmate::assert_list(decorators, "teal_transform_module")
# End of assertions

# Make UI args
Expand All @@ -288,7 +300,8 @@ tm_g_bivariate <- function(label = "Bivariate Plots",
ui_args = args,
server_args = c(
data_extract_list,
list(plot_height = plot_height, plot_width = plot_width, ggplot2_args = ggplot2_args)
list(plot_height = plot_height, plot_width = plot_width, ggplot2_args = ggplot2_args),
decorators = decorators
),
datanames = teal.transform::get_extract_datanames(data_extract_list)
)
Expand Down Expand Up @@ -338,6 +351,7 @@ ui_g_bivariate <- function(id, ...) {
justified = TRUE
)
),
ui_teal_transform_data(ns("decorate"), transformators = args$decorators),
if (!is.null(args$row_facet) || !is.null(args$col_facet)) {
tags$div(
class = "data-extract-box",
Expand Down Expand Up @@ -451,7 +465,8 @@ srv_g_bivariate <- function(id,
size,
plot_height,
plot_width,
ggplot2_args) {
ggplot2_args,
decorators) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "reactive")
Expand Down Expand Up @@ -654,31 +669,33 @@ srv_g_bivariate <- function(id,
without_facet <- (is.null(nulled_row_facet_name) && is.null(nulled_col_facet_name)) || !facetting

print_call <- if (without_facet) {
quote(print(p))
quote(print(plot))
} else {
substitute(
expr = {
# Add facetting labels
# optional: grid.newpage() # nolint: commented_code.
# Prefixed with teal.modules.general as its usage will appear in "Show R code"
p <- teal.modules.general::add_facet_labels(
p,
plot <- teal.modules.general::add_facet_labels(
plot,
xfacet_label = nulled_col_facet_name,
yfacet_label = nulled_row_facet_name
)
grid::grid.newpage()
grid::grid.draw(p)
grid::grid.draw(plot)
},
env = list(nulled_col_facet_name = nulled_col_facet_name, nulled_row_facet_name = nulled_row_facet_name)
)
}

teal.code::eval_code(merged$anl_q_r(), substitute(expr = p <- cl, env = list(cl = cl))) %>%
teal.code::eval_code(merged$anl_q_r(), substitute(expr = plot <- cl, env = list(cl = cl))) %>%
teal.code::eval_code(print_call)
})

decorated_output_q <- srv_teal_transform_data("decorate", data = output_q, transformators = decorators)

plot_r <- reactive({
output_q()[["p"]]
decorated_output_q()[["plot"]]
})

pws <- teal.widgets::plot_with_settings_srv(
Expand All @@ -690,7 +707,7 @@ srv_g_bivariate <- function(id,

teal.widgets::verbatim_popup_srv(
id = "rcode",
verbatim_content = reactive(teal.code::get_code(output_q())),
verbatim_content = reactive(teal.code::get_code(req(decorated_output_q()))),
title = "Bivariate Plot"
)

Expand Down
Loading