From da7053bb4205ed64f100ef8839baa88cf0eb6103 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Thu, 26 Oct 2023 18:06:29 -0400 Subject: [PATCH 1/4] Add option to remove interval in tm_g_lineplot --- NEWS.md | 1 + R/tm_g_lineplot.R | 27 +++++++++++++++------------ man/template_g_lineplot.Rd | 10 ++++++---- man/tm_g_lineplot.Rd | 10 ++++++---- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8eaa63bf8f..98f32e22fb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,7 @@ * Updated `tm_t_coxreg` to drop factor covariate variable levels that are not present to avoid errors when filtering. * Updated `tm_t_pp_basic_info`, `tm_t_pp_medical_history`, `tm_g_pp_therapy`, `tm_g_pp_adverse_events`, and `tm_t_pp_laboratory` to print patient ID above table. * Updated `tm_t_pp_basic_info`, `tm_g_pp_therapy`, `tm_g_pp_adverse_events`, and `tm_t_pp_laboratory` to use `rlistings` to print data neatly in reports. +* Updated `tm_g_lineplot` to allow user to remove interval from plot. ### Bug fixes diff --git a/R/tm_g_lineplot.R b/R/tm_g_lineplot.R index fced62f2a1..d4123ee889 100644 --- a/R/tm_g_lineplot.R +++ b/R/tm_g_lineplot.R @@ -121,12 +121,16 @@ template_g_lineplot <- function(dataname = "ANL", user_plot = ggplot2_args, module_plot = teal.widgets::ggplot2_args( labs = list( - title = sprintf( - "Plot of %s and %s %s of %s by Visit", - names(which(mid_choices == mid)), - `if`(interval %in% c("mean_ci", "median_ci"), paste0(conf_level * 100, "%"), ""), - names(which(interval_choices == interval)), - y + title = paste0( + "Plot of ", names(which(mid_choices == mid)), + if (!is.null(interval)) { + paste0( + " and ", + if (interval %in% c("mean_ci", "median_ci")) paste0(conf_level * 100, "% "), + names(which(interval_choices == interval)) + ) + }, + " of ", y, " by Visit" ), subtitle = "", y = sprintf("%s %s Values for", y, names(which(mid_choices == mid))) @@ -291,7 +295,7 @@ tm_g_lineplot <- function(label, checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_string(mid) - checkmate::assert_string(interval) + checkmate::assert_string(interval, null.ok = TRUE) whiskers <- match.arg(whiskers) checkmate::assert_class(conf_level, "choices_selected") checkmate::assert_numeric(plot_height, len = 3, any.missing = FALSE, finite = TRUE) @@ -542,8 +546,6 @@ srv_g_lineplot <- function(id, message_fmt = "Please choose a confidence level between 0 and 1", inclusive = c(FALSE, FALSE) ) ) - iv$add_rule("interval", shinyvalidate::sv_required("Please select an interval for the midpoint statistic")) - iv$add_rule("whiskers", shinyvalidate::sv_required("At least one of the whiskers must be selected")) teal.transform::compose_and_enable_validators(iv, selector_list) }) @@ -597,9 +599,10 @@ srv_g_lineplot <- function(id, ANL <- merged$anl_q()[["ANL"]] # nolint teal::validate_has_data(ANL, 2) - whiskers_selected <- ifelse(input$whiskers == "Lower", 1, ifelse(input$whiskers == "Upper", 2, 1:2)) - input_whiskers <- names(tern::s_summary(0)[[input$interval]][whiskers_selected]) - input_interval <- input$interval + whiskers_selected <- if ("Lower" %in% input$whiskers) 1 else NULL + if ("Upper" %in% input$whiskers) whiskers_selected <- c(whiskers_selected, 2) + input_interval <- if (is.null(whiskers_selected)) NULL else input$interval + input_whiskers <- if (is.null(input_interval)) NULL else names(tern::s_summary(0)[[input_interval]][whiskers_selected]) input_param <- as.character(unique(ANL[[names(merged$anl_input_r()$columns_source$param)[1]]])) my_calls <- template_g_lineplot( diff --git a/man/template_g_lineplot.Rd b/man/template_g_lineplot.Rd index 149a4fc47e..1e6f07cc48 100644 --- a/man/template_g_lineplot.Rd +++ b/man/template_g_lineplot.Rd @@ -49,11 +49,13 @@ and be of a \code{double} or \code{numeric} type vector of length one.} \item{interval}{(\code{character} or \code{NULL})\cr names of the statistics that will be plotted as intervals. All the statistics indicated in \code{interval} variable must be present in the object returned by \code{sfun}, -and be of a \code{double} or \code{numeric} type vector of length two.} +and be of a \code{double} or \code{numeric} type vector of length two. Set \code{interval = NULL} if intervals should not be +added to the plot.} -\item{whiskers}{(\code{character})\cr names of the interval whiskers that will be plotted. Must match the \code{names} -attribute of the \code{interval} element in the list returned by \code{sfun}. It is possible to specify one whisker only, -lower or upper.} +\item{whiskers}{(\code{character})\cr names of the interval whiskers that will be plotted. Names must match names +of the list element \code{interval} that will be returned by \code{sfun} (e.g. \code{mean_ci_lwr} element of +\code{sfun(x)[["mean_ci"]]}). It is possible to specify one whisker only, or to suppress all whiskers by setting +\code{interval = NULL}.} \item{table}{(\code{character} or \code{NULL})\cr names of the statistics that will be displayed in the table below the plot. All the statistics indicated in \code{table} variable must be present in the object returned by \code{sfun}.} diff --git a/man/tm_g_lineplot.Rd b/man/tm_g_lineplot.Rd index bde659f9f7..13b5e21b8e 100644 --- a/man/tm_g_lineplot.Rd +++ b/man/tm_g_lineplot.Rd @@ -65,15 +65,17 @@ value for the confidence level within the range of (0, 1).} \item{interval}{(\code{character} or \code{NULL})\cr names of the statistics that will be plotted as intervals. All the statistics indicated in \code{interval} variable must be present in the object returned by \code{sfun}, -and be of a \code{double} or \code{numeric} type vector of length two.} +and be of a \code{double} or \code{numeric} type vector of length two. Set \code{interval = NULL} if intervals should not be +added to the plot.} \item{mid}{(\code{character} or \code{NULL})\cr names of the statistics that will be plotted as midpoints. All the statistics indicated in \code{mid} variable must be present in the object returned by \code{sfun}, and be of a \code{double} or \code{numeric} type vector of length one.} -\item{whiskers}{(\code{character})\cr names of the interval whiskers that will be plotted. Must match the \code{names} -attribute of the \code{interval} element in the list returned by \code{sfun}. It is possible to specify one whisker only, -lower or upper.} +\item{whiskers}{(\code{character})\cr names of the interval whiskers that will be plotted. Names must match names +of the list element \code{interval} that will be returned by \code{sfun} (e.g. \code{mean_ci_lwr} element of +\code{sfun(x)[["mean_ci"]]}). It is possible to specify one whisker only, or to suppress all whiskers by setting +\code{interval = NULL}.} \item{table}{(\code{character} or \code{NULL})\cr names of the statistics that will be displayed in the table below the plot. All the statistics indicated in \code{table} variable must be present in the object returned by \code{sfun}.} From d5efe79361e5f5bf399853beeeafaa714e104bf3 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Thu, 26 Oct 2023 18:29:41 -0400 Subject: [PATCH 2/4] Fix lint --- R/tm_g_lineplot.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/tm_g_lineplot.R b/R/tm_g_lineplot.R index d4123ee889..968988706b 100644 --- a/R/tm_g_lineplot.R +++ b/R/tm_g_lineplot.R @@ -602,7 +602,11 @@ srv_g_lineplot <- function(id, whiskers_selected <- if ("Lower" %in% input$whiskers) 1 else NULL if ("Upper" %in% input$whiskers) whiskers_selected <- c(whiskers_selected, 2) input_interval <- if (is.null(whiskers_selected)) NULL else input$interval - input_whiskers <- if (is.null(input_interval)) NULL else names(tern::s_summary(0)[[input_interval]][whiskers_selected]) + input_whiskers <- if (is.null(input_interval)) { + NULL + } else { + names(tern::s_summary(0)[[input_interval]][whiskers_selected]) + } input_param <- as.character(unique(ANL[[names(merged$anl_input_r()$columns_source$param)[1]]])) my_calls <- template_g_lineplot( From 03ba856c8150ea8bebafa5afdd5e95cc1fad22bc Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Fri, 27 Oct 2023 15:04:33 -0400 Subject: [PATCH 3/4] Update after review suggestions --- R/tm_g_lineplot.R | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/R/tm_g_lineplot.R b/R/tm_g_lineplot.R index 968988706b..28e10102d4 100644 --- a/R/tm_g_lineplot.R +++ b/R/tm_g_lineplot.R @@ -436,8 +436,8 @@ ui_g_lineplot <- function(id, ...) { shiny::checkboxGroupInput( ns("whiskers"), "Whiskers to display", - choices = c("Lower", "Upper"), - selected = c("Lower", "Upper") + choices = c("Upper", "Lower"), + selected = c("Upper", "Lower") ), shiny::radioButtons( ns("mid_type"), @@ -601,11 +601,12 @@ srv_g_lineplot <- function(id, whiskers_selected <- if ("Lower" %in% input$whiskers) 1 else NULL if ("Upper" %in% input$whiskers) whiskers_selected <- c(whiskers_selected, 2) - input_interval <- if (is.null(whiskers_selected)) NULL else input$interval - input_whiskers <- if (is.null(input_interval)) { - NULL + if (is.null(input$interval) || is.null(whiskers_selected)) { + input_whiskers <- NULL + input_interval <- NULL } else { - names(tern::s_summary(0)[[input_interval]][whiskers_selected]) + input_interval <- input$interval + input_whiskers <- names(tern::s_summary(0)[[input_interval]][whiskers_selected]) } input_param <- as.character(unique(ANL[[names(merged$anl_input_r()$columns_source$param)[1]]])) From c176349ab34682cdd9da8a01847791a1bc0b28ec Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Fri, 27 Oct 2023 18:14:03 -0400 Subject: [PATCH 4/4] Empty commit