From f52dd20f247502e30da0935b2acd48dc65e74a71 Mon Sep 17 00:00:00 2001 From: kartikeya kirar Date: Thu, 6 Jun 2024 17:45:15 +0530 Subject: [PATCH] 271: Removed dataset name displayed in dropdown menus (#279) fixes: https://github.com/insightsengineering/teal.goshawk/issues/271 --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- R/tm_g_gh_boxplot.R | 4 ++-- R/tm_g_gh_correlationplot.R | 2 +- R/tm_g_gh_density_distribution_plot.R | 2 +- R/tm_g_gh_lineplot.R | 4 ++-- R/tm_g_gh_scatterplot.R | 2 +- R/tm_g_gh_spaghettiplot.R | 2 +- R/utils.R | 17 +++++++++++++++++ man/get_choices.Rd | 20 ++++++++++++++++++++ 8 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 man/get_choices.Rd diff --git a/R/tm_g_gh_boxplot.R b/R/tm_g_gh_boxplot.R index 8688687b..77b764aa 100644 --- a/R/tm_g_gh_boxplot.R +++ b/R/tm_g_gh_boxplot.R @@ -251,7 +251,7 @@ ui_g_boxplot <- function(id, ...) { teal.widgets::optionalSelectInput( ns("trt_group"), label = "Select Treatment Variable", - choices = a$trt_group$choices, + choices = get_choices(a$trt_group$choices), selected = a$trt_group$selected, multiple = FALSE ), @@ -259,7 +259,7 @@ ui_g_boxplot <- function(id, ...) { teal.widgets::optionalSelectInput( ns("facet_var"), label = "Facet by", - choices = a$facet_var$choices, + choices = get_choices(a$facet_var$choices), selected = a$facet_var$selected, multiple = FALSE ), diff --git a/R/tm_g_gh_correlationplot.R b/R/tm_g_gh_correlationplot.R index 77da6ddf..09999d63 100644 --- a/R/tm_g_gh_correlationplot.R +++ b/R/tm_g_gh_correlationplot.R @@ -286,7 +286,7 @@ ui_g_correlationplot <- function(id, ...) { teal.widgets::optionalSelectInput( ns("trt_group"), label = "Select Treatment Variable", - choices = a$trt_group$choices, + choices = get_choices(a$trt_group$choices), selected = a$trt_group$selected, multiple = FALSE ), diff --git a/R/tm_g_gh_density_distribution_plot.R b/R/tm_g_gh_density_distribution_plot.R index 0d421d4a..c190371b 100644 --- a/R/tm_g_gh_density_distribution_plot.R +++ b/R/tm_g_gh_density_distribution_plot.R @@ -199,7 +199,7 @@ ui_g_density_distribution_plot <- function(id, ...) { teal.widgets::optionalSelectInput( ns("trt_group"), label = "Select Treatment Variable", - choices = a$trt_group$choices, + choices = get_choices(a$trt_group$choices), selected = a$trt_group$selected, multiple = FALSE ), diff --git a/R/tm_g_gh_lineplot.R b/R/tm_g_gh_lineplot.R index afb65fea..63e2b3cb 100644 --- a/R/tm_g_gh_lineplot.R +++ b/R/tm_g_gh_lineplot.R @@ -243,7 +243,7 @@ ui_lineplot <- function(id, ...) { teal.widgets::optionalSelectInput( ns("trt_group"), label = "Select Treatment Variable", - choices = a$trt_group$choices, + choices = get_choices(a$trt_group$choices), selected = a$trt_group$selected, multiple = FALSE ), @@ -380,7 +380,7 @@ srv_lineplot <- function(id, output$shape_ui <- renderUI({ if (!is.null(shape_choices)) { if (methods::is(shape_choices, "choices_selected")) { - choices <- shape_choices$choices + choices <- get_choices(shape_choices$choices) selected <- shape_choices$selected } else { choices <- shape_choices diff --git a/R/tm_g_gh_scatterplot.R b/R/tm_g_gh_scatterplot.R index 29d31f1c..3d5009a2 100644 --- a/R/tm_g_gh_scatterplot.R +++ b/R/tm_g_gh_scatterplot.R @@ -199,7 +199,7 @@ ui_g_scatterplot <- function(id, ...) { teal.widgets::optionalSelectInput( ns("trt_group"), label = "Select Treatment Variable", - choices = a$trt_group$choices, + choices = get_choices(a$trt_group$choices), selected = a$trt_group$selected, multiple = FALSE ), diff --git a/R/tm_g_gh_spaghettiplot.R b/R/tm_g_gh_spaghettiplot.R index afcf9152..e124bad4 100644 --- a/R/tm_g_gh_spaghettiplot.R +++ b/R/tm_g_gh_spaghettiplot.R @@ -281,7 +281,7 @@ g_ui_spaghettiplot <- function(id, ...) { teal.widgets::optionalSelectInput( ns("trt_group"), label = "Select Treatment Variable", - choices = a$trt_group$choices, + choices = get_choices(a$trt_group$choices), selected = a$trt_group$selected, multiple = FALSE ), diff --git a/R/utils.R b/R/utils.R index 89490753..a8fec2b8 100644 --- a/R/utils.R +++ b/R/utils.R @@ -82,3 +82,20 @@ report_card_template_goshawk <- function(title, ) card } + +#' Get Choices +#' +#' This function returns choices based on the class of the input. +#' If the input is of class `delayed_data`, it returns the `subset` of the input. +#' Otherwise, it returns the input as is. +#' +#' @param choices An object that contains choices. +#' @return A vector of choices. +#' @keywords internal +get_choices <- function(choices) { + if (inherits(choices, "delayed_data")) { + choices$subset + } else { + choices + } +} diff --git a/man/get_choices.Rd b/man/get_choices.Rd new file mode 100644 index 00000000..56cd5af1 --- /dev/null +++ b/man/get_choices.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{get_choices} +\alias{get_choices} +\title{Get Choices} +\usage{ +get_choices(choices) +} +\arguments{ +\item{choices}{An object that contains choices.} +} +\value{ +A vector of choices. +} +\description{ +This function returns choices based on the class of the input. +If the input is of class \code{delayed_data}, it returns the \code{subset} of the input. +Otherwise, it returns the input as is. +} +\keyword{internal}