From fe05e76f8b69b304457cb6b198c85b93812ff97e Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Mon, 18 Mar 2024 14:47:30 +0100 Subject: [PATCH] few enhancements (#254) - fixed package level Rd file - removed unnecessary empty first line in examples as this is actually being rendered - removed `pkg::` from docs for packages in Depends - fixed example of `toggle_slider_ui` --------- Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: unknown Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- R/teal_goshawk.R | 3 +- R/tm_g_gh_boxplot.R | 37 +++++----- R/tm_g_gh_correlationplot.R | 49 +++++++------ R/tm_g_gh_density_distribution_plot.R | 23 ++++--- R/tm_g_gh_lineplot.R | 21 +++--- R/tm_g_gh_scatterplot.R | 30 ++++---- R/tm_g_gh_spaghettiplot.R | 37 +++++----- R/toggleable_slider.R | 68 ++++++++----------- R/utils-maptrt.r | 3 +- man/maptrt.Rd | 3 +- ...eal_goshawk.Rd => teal.goshawk-package.Rd} | 3 +- man/tm_g_gh_boxplot.Rd | 37 +++++----- man/tm_g_gh_correlationplot.Rd | 49 +++++++------ man/tm_g_gh_density_distribution_plot.Rd | 23 ++++--- man/tm_g_gh_lineplot.Rd | 21 +++--- man/tm_g_gh_scatterplot.Rd | 30 ++++---- man/tm_g_gh_spaghettiplot.Rd | 37 +++++----- man/toggle_slider_ui.Rd | 68 ++++++++----------- 18 files changed, 272 insertions(+), 270 deletions(-) rename man/{teal_goshawk.Rd => teal.goshawk-package.Rd} (97%) diff --git a/R/teal_goshawk.R b/R/teal_goshawk.R index a783225b..e246fb95 100644 --- a/R/teal_goshawk.R +++ b/R/teal_goshawk.R @@ -5,8 +5,6 @@ #' The data used for teal.goshawk have some constraints. #' It must contain the columns `AVISITCD`, `BASE`, `BASE2`, `AVALU`, `LBSTRESC`, `LOQFL`, `CHG2`, and `PCHG2`. #' -#' @name teal_goshawk -#' #' @import goshawk #' @import shiny #' @import teal @@ -14,5 +12,6 @@ #' @importFrom ggplot2 ggplot #' @importFrom rlang .data sym #' @importFrom teal.transform choices_selected +#' #' @keywords internal "_PACKAGE" diff --git a/R/tm_g_gh_boxplot.R b/R/tm_g_gh_boxplot.R index c1e37558..1d463e48 100644 --- a/R/tm_g_gh_boxplot.R +++ b/R/tm_g_gh_boxplot.R @@ -46,12 +46,15 @@ #' @export #' #' @examples -#' #' # Example using ADaM structure analysis dataset. #' data <- teal_data() #' data <- within(data, { #' library(dplyr) #' library(nestcolor) +#' library(stringr) +#' +#' # use non-exported function from goshawk +#' h_identify_loq_values <- getFromNamespace("h_identify_loq_values", "goshawk") #' #' # original ARM value = dose value #' arm_mapping <- list( @@ -60,25 +63,25 @@ #' "C: Combination" = "Combination" #' ) #' set.seed(1) -#' ADSL <- goshawk::rADSL -#' ADLB <- goshawk::rADLB +#' ADSL <- rADSL +#' ADLB <- rADLB #' var_labels <- lapply(ADLB, function(x) attributes(x)$label) #' ADLB <- ADLB %>% -#' dplyr::mutate( -#' AVISITCD = dplyr::case_when( +#' mutate( +#' AVISITCD = case_when( #' AVISIT == "SCREENING" ~ "SCR", #' AVISIT == "BASELINE" ~ "BL", -#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), +#' grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), #' TRUE ~ as.character(NA) #' ), -#' AVISITCDN = dplyr::case_when( +#' AVISITCDN = case_when( #' AVISITCD == "SCR" ~ -2, #' AVISITCD == "BL" ~ 0, #' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), #' TRUE ~ as.numeric(NA) #' ), #' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( +#' TRTORD = case_when( #' ARMCD == "ARM C" ~ 1, #' ARMCD == "ARM B" ~ 2, #' ARMCD == "ARM A" ~ 3 @@ -90,13 +93,13 @@ #' ANRLO = 50, #' ANRHI = 75 #' ) %>% -#' dplyr::rowwise() %>% -#' dplyr::group_by(PARAMCD) %>% -#' dplyr::mutate(LBSTRESC = ifelse( +#' rowwise() %>% +#' group_by(PARAMCD) %>% +#' mutate(LBSTRESC = ifelse( #' USUBJID %in% sample(USUBJID, 1, replace = TRUE), #' paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC #' )) %>% -#' dplyr::mutate(LBSTRESC = ifelse( +#' mutate(LBSTRESC = ifelse( #' USUBJID %in% sample(USUBJID, 1, replace = TRUE), #' paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC #' )) %>% @@ -108,8 +111,8 @@ #' attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" #' #' # add LLOQ and ULOQ variables -#' ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB, "LOQFL") -#' ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM") +#' ALB_LOQS <- h_identify_loq_values(ADLB, "LOQFL") +#' ADLB <- left_join(ADLB, ALB_LOQS, by = "PARAM") #' }) #' #' datanames <- c("ADSL", "ADLB") @@ -117,10 +120,10 @@ #' #' join_keys(data) <- default_cdisc_join_keys[datanames] #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( -#' teal.goshawk::tm_g_gh_boxplot( +#' modules = modules( +#' tm_g_gh_boxplot( #' label = "Box Plot", #' dataname = "ADLB", #' param_var = "PARAMCD", diff --git a/R/tm_g_gh_correlationplot.R b/R/tm_g_gh_correlationplot.R index e99bee10..9b661014 100644 --- a/R/tm_g_gh_correlationplot.R +++ b/R/tm_g_gh_correlationplot.R @@ -50,10 +50,15 @@ #' @author Balazs Toth (tothb2) toth.balazs@gene.com #' #' @examples -#' #' # Example using ADaM structure analysis dataset. #' data <- teal_data() #' data <- within(data, { +#' library(dplyr) +#' library(stringr) +#' +#' # use non-exported function from goshawk +#' h_identify_loq_values <- getFromNamespace("h_identify_loq_values", "goshawk") +#' #' # original ARM value = dose value #' arm_mapping <- list( #' "A: Drug X" = "150mg QD", @@ -65,11 +70,11 @@ #' shape_manual <- c("N" = 1, "Y" = 2, "NA" = 0) #' #' set.seed(1) -#' ADSL <- goshawk::rADSL -#' ADLB <- goshawk::rADLB +#' ADSL <- rADSL +#' ADLB <- rADLB #' var_labels <- lapply(ADLB, function(x) attributes(x)$label) #' ADLB <- ADLB %>% -#' dplyr::mutate(AVISITCD = dplyr::case_when( +#' mutate(AVISITCD = case_when( #' AVISIT == "SCREENING" ~ "SCR", #' AVISIT == "BASELINE" ~ "BL", #' grepl("WEEK", AVISIT) ~ @@ -79,48 +84,48 @@ #' substr( #' AVISIT, #' start = 6, -#' stop = stringr::str_locate(AVISIT, "DAY") - 1 +#' stop = str_locate(AVISIT, "DAY") - 1 #' ) #' ) #' ), #' TRUE ~ NA_character_ #' )) %>% -#' dplyr::mutate(AVISITCDN = dplyr::case_when( +#' mutate(AVISITCDN = case_when( #' AVISITCD == "SCR" ~ -2, #' AVISITCD == "BL" ~ 0, #' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), #' TRUE ~ NA_real_ #' )) %>% #' # use ARMCD values to order treatment in visualization legend -#' dplyr::mutate(TRTORD = ifelse(grepl("C", ARMCD), 1, +#' mutate(TRTORD = ifelse(grepl("C", ARMCD), 1, #' ifelse(grepl("B", ARMCD), 2, #' ifelse(grepl("A", ARMCD), 3, NA) #' ) #' )) %>% -#' dplyr::mutate(ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))])) %>% -#' dplyr::mutate(ARM = factor(ARM) %>% +#' mutate(ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))])) %>% +#' mutate(ARM = factor(ARM) %>% #' reorder(TRTORD)) %>% -#' dplyr::mutate( -#' ANRHI = dplyr::case_when( +#' mutate( +#' ANRHI = case_when( #' PARAMCD == "ALT" ~ 60, #' PARAMCD == "CRP" ~ 70, #' PARAMCD == "IGA" ~ 80, #' TRUE ~ NA_real_ #' ), -#' ANRLO = dplyr::case_when( +#' ANRLO = case_when( #' PARAMCD == "ALT" ~ 20, #' PARAMCD == "CRP" ~ 30, #' PARAMCD == "IGA" ~ 40, #' TRUE ~ NA_real_ #' ) #' ) %>% -#' dplyr::rowwise() %>% -#' dplyr::group_by(PARAMCD) %>% -#' dplyr::mutate(LBSTRESC = ifelse( +#' rowwise() %>% +#' group_by(PARAMCD) %>% +#' mutate(LBSTRESC = ifelse( #' USUBJID %in% sample(USUBJID, 1, replace = TRUE), #' paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC #' )) %>% -#' dplyr::mutate(LBSTRESC = ifelse( +#' mutate(LBSTRESC = ifelse( #' USUBJID %in% sample(USUBJID, 1, replace = TRUE), #' paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC #' )) %>% @@ -130,8 +135,8 @@ #' attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" #' #' # add LLOQ and ULOQ variables -#' ADLB_LOQS <- goshawk:::h_identify_loq_values(ADLB, "LOQFL") -#' ADLB <- dplyr::left_join(ADLB, ADLB_LOQS, by = "PARAM") +#' ADLB_LOQS <- h_identify_loq_values(ADLB, "LOQFL") +#' ADLB <- left_join(ADLB, ADLB_LOQS, by = "PARAM") #' }) #' #' datanames <- c("ADSL", "ADLB") @@ -139,10 +144,10 @@ #' #' join_keys(data) <- default_cdisc_join_keys[datanames] #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( -#' teal.goshawk::tm_g_gh_correlationplot( +#' modules = modules( +#' tm_g_gh_correlationplot( #' label = "Correlation Plot", #' dataname = "ADLB", #' param_var = "PARAMCD", @@ -170,7 +175,7 @@ #' hline_arb_color = c("red", "blue"), #' hline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"), #' hline_vars_colors = c("green", "blue", "purple", "cyan"), -#' hline_vars_label = c("ANRHI Label", "ANRLO Label", "ULOQN Label", "LLOQN Label"), +#' hline_vars_labels = c("ANRHI Label", "ANRLO Label", "ULOQN Label", "LLOQN Label"), #' vline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"), #' vline_vars_colors = c("yellow", "orange", "brown", "gold"), #' vline_vars_labels = c("ANRHI Label", "ANRLO Label", "ULOQN Label", "LLOQN Label"), diff --git a/R/tm_g_gh_density_distribution_plot.R b/R/tm_g_gh_density_distribution_plot.R index a3f50e0b..86fc2322 100644 --- a/R/tm_g_gh_density_distribution_plot.R +++ b/R/tm_g_gh_density_distribution_plot.R @@ -33,36 +33,37 @@ #' @export #' #' @examples -#' #' # Example using ADaM structure analysis dataset. #' data <- teal_data() #' data <- within(data, { #' library(dplyr) +#' library(stringr) +#' #' # original ARM value = dose value #' arm_mapping <- list( #' "A: Drug X" = "150mg QD", #' "B: Placebo" = "Placebo", #' "C: Combination" = "Combination" #' ) -#' ADSL <- goshawk::rADSL -#' ADLB <- goshawk::rADLB +#' ADSL <- rADSL +#' ADLB <- rADLB #' var_labels <- lapply(ADLB, function(x) attributes(x)$label) #' ADLB <- ADLB %>% -#' dplyr::mutate( -#' AVISITCD = dplyr::case_when( +#' mutate( +#' AVISITCD = case_when( #' AVISIT == "SCREENING" ~ "SCR", #' AVISIT == "BASELINE" ~ "BL", -#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), +#' grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), #' TRUE ~ as.character(NA) #' ), -#' AVISITCDN = dplyr::case_when( +#' AVISITCDN = case_when( #' AVISITCD == "SCR" ~ -2, #' AVISITCD == "BL" ~ 0, #' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), #' TRUE ~ as.numeric(NA) #' ), #' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( +#' TRTORD = case_when( #' ARMCD == "ARM C" ~ 1, #' ARMCD == "ARM B" ~ 2, #' ARMCD == "ARM A" ~ 3 @@ -81,10 +82,10 @@ #' datanames(data) <- datanames #' join_keys(data) <- default_cdisc_join_keys[datanames] #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( -#' teal.goshawk::tm_g_gh_density_distribution_plot( +#' modules = modules( +#' tm_g_gh_density_distribution_plot( #' label = "Density Distribution Plot", #' dataname = "ADLB", #' param_var = "PARAMCD", diff --git a/R/tm_g_gh_lineplot.R b/R/tm_g_gh_lineplot.R index 639c754f..492edd93 100644 --- a/R/tm_g_gh_lineplot.R +++ b/R/tm_g_gh_lineplot.R @@ -51,7 +51,6 @@ #' @export #' #' @examples -#' #' # Example using ADaM structure analysis dataset. #' data <- teal_data() #' data <- within(data, { @@ -66,25 +65,25 @@ #' "C: Combination" = "Combination" #' ) #' -#' ADSL <- goshawk::rADSL -#' ADLB <- goshawk::rADLB +#' ADSL <- rADSL +#' ADLB <- rADLB #' var_labels <- lapply(ADLB, function(x) attributes(x)$label) #' ADLB <- ADLB %>% -#' dplyr::mutate( -#' AVISITCD = dplyr::case_when( +#' mutate( +#' AVISITCD = case_when( #' AVISIT == "SCREENING" ~ "SCR", #' AVISIT == "BASELINE" ~ "BL", -#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), +#' grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), #' TRUE ~ as.character(NA) #' ), -#' AVISITCDN = dplyr::case_when( +#' AVISITCDN = case_when( #' AVISITCD == "SCR" ~ -2, #' AVISITCD == "BL" ~ 0, #' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), #' TRUE ~ as.numeric(NA) #' ), #' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( +#' TRTORD = case_when( #' ARMCD == "ARM C" ~ 1, #' ARMCD == "ARM B" ~ 2, #' ARMCD == "ARM A" ~ 3 @@ -102,10 +101,10 @@ #' datanames(data) <- datanames #' join_keys(data) <- default_cdisc_join_keys[datanames] #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( -#' teal.goshawk::tm_g_gh_lineplot( +#' modules = modules( +#' tm_g_gh_lineplot( #' label = "Line Plot", #' dataname = "ADLB", #' param_var = "PARAMCD", diff --git a/R/tm_g_gh_scatterplot.R b/R/tm_g_gh_scatterplot.R index 8893d33e..f36d3314 100644 --- a/R/tm_g_gh_scatterplot.R +++ b/R/tm_g_gh_scatterplot.R @@ -38,10 +38,12 @@ #' @author Balazs Toth (tothb2) toth.balazs@gene.com #' #' @examples -#' #' # Example using ADaM structure analysis dataset. #' data <- teal_data() #' data <- within(data, { +#' library(dplyr) +#' library(stringr) +#' #' # original ARM value = dose value #' arm_mapping <- list( #' "A: Drug X" = "150mg QD", @@ -49,33 +51,33 @@ #' "C: Combination" = "Combination" #' ) #' -#' ADSL <- goshawk::rADSL -#' ADLB <- goshawk::rADLB +#' ADSL <- rADSL +#' ADLB <- rADLB #' var_labels <- lapply(ADLB, function(x) attributes(x)$label) #' ADLB <- ADLB %>% -#' dplyr::mutate( -#' AVISITCD = dplyr::case_when( +#' mutate( +#' AVISITCD = case_when( #' AVISIT == "SCREENING" ~ "SCR", #' AVISIT == "BASELINE" ~ "BL", -#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), +#' grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), #' TRUE ~ as.character(NA) #' ), -#' AVISITCDN = dplyr::case_when( +#' AVISITCDN = case_when( #' AVISITCD == "SCR" ~ -2, #' AVISITCD == "BL" ~ 0, #' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), #' TRUE ~ as.numeric(NA) #' ), -#' AVISITCD = factor(AVISITCD) %>% stats::reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( +#' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), +#' TRTORD = case_when( #' ARMCD == "ARM C" ~ 1, #' ARMCD == "ARM B" ~ 2, #' ARMCD == "ARM A" ~ 3 #' ), #' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), -#' ARM = factor(ARM) %>% stats::reorder(TRTORD), +#' ARM = factor(ARM) %>% reorder(TRTORD), #' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), -#' ACTARM = factor(ACTARM) %>% stats::reorder(TRTORD) +#' ACTARM = factor(ACTARM) %>% reorder(TRTORD) #' ) #' attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] #' attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] @@ -86,10 +88,10 @@ #' join_keys(data) <- default_cdisc_join_keys[datanames] #' #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( -#' teal.goshawk::tm_g_gh_scatterplot( +#' modules = modules( +#' tm_g_gh_scatterplot( #' label = "Scatter Plot", #' dataname = "ADLB", #' param_var = "PARAMCD", diff --git a/R/tm_g_gh_spaghettiplot.R b/R/tm_g_gh_spaghettiplot.R index ee210005..4f5d42e2 100644 --- a/R/tm_g_gh_spaghettiplot.R +++ b/R/tm_g_gh_spaghettiplot.R @@ -55,11 +55,14 @@ #' @export #' #' @examples -#' #' # Example using ADaM structure analysis dataset. #' data <- teal_data() #' data <- within(data, { #' library(dplyr) +#' library(stringr) +#' +#' # use non-exported function from goshawk +#' h_identify_loq_values <- getFromNamespace("h_identify_loq_values", "goshawk") #' #' # original ARM value = dose value #' arm_mapping <- list( @@ -68,25 +71,25 @@ #' "C: Combination" = "Combination" #' ) #' set.seed(1) -#' ADSL <- goshawk::rADSL -#' ADLB <- goshawk::rADLB +#' ADSL <- rADSL +#' ADLB <- rADLB #' var_labels <- lapply(ADLB, function(x) attributes(x)$label) #' ADLB <- ADLB %>% -#' dplyr::mutate( -#' AVISITCD = dplyr::case_when( +#' mutate( +#' AVISITCD = case_when( #' AVISIT == "SCREENING" ~ "SCR", #' AVISIT == "BASELINE" ~ "BL", -#' grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), +#' grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), #' TRUE ~ as.character(NA) #' ), -#' AVISITCDN = dplyr::case_when( +#' AVISITCDN = case_when( #' AVISITCD == "SCR" ~ -2, #' AVISITCD == "BL" ~ 0, #' grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), #' TRUE ~ as.numeric(NA) #' ), #' AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), -#' TRTORD = dplyr::case_when( +#' TRTORD = case_when( #' ARMCD == "ARM C" ~ 1, #' ARMCD == "ARM B" ~ 2, #' ARMCD == "ARM A" ~ 3 @@ -98,12 +101,12 @@ #' ANRLO = 30, #' ANRHI = 75 #' ) %>% -#' dplyr::rowwise() %>% -#' dplyr::group_by(PARAMCD) %>% -#' dplyr::mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), +#' rowwise() %>% +#' group_by(PARAMCD) %>% +#' mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), #' paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC #' )) %>% -#' dplyr::mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), +#' mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), #' paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC #' )) %>% #' ungroup() @@ -113,18 +116,18 @@ #' attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" #' #' # add LLOQ and ULOQ variables -#' ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB, "LOQFL") -#' ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM") +#' ALB_LOQS <- h_identify_loq_values(ADLB, "LOQFL") +#' ADLB <- left_join(ADLB, ALB_LOQS, by = "PARAM") #' }) #' #' datanames <- c("ADSL", "ADLB") #' datanames(data) <- datanames #' join_keys(data) <- default_cdisc_join_keys[datanames] #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( -#' teal.goshawk::tm_g_gh_spaghettiplot( +#' modules = modules( +#' tm_g_gh_spaghettiplot( #' label = "Spaghetti Plot", #' dataname = "ADLB", #' param_var = "PARAMCD", diff --git a/R/toggleable_slider.R b/R/toggleable_slider.R index a68081f4..1fb9a986 100644 --- a/R/toggleable_slider.R +++ b/R/toggleable_slider.R @@ -28,47 +28,37 @@ #' @examples #' value <- c(20.3, 81.5) # dichotomous slider #' # value <- c(50.1) # normal slider -#' app <- shinyApp( -#' ui = tags$div( -#' teal.goshawk:::toggle_slider_ui( -#' "toggle_slider", "Select value", -#' min = 0.2, max = 100.1, value = value, -#' slider_initially = FALSE, step_slider = 0.1, step_numeric = 0.001 -#' ), -#' verbatimTextOutput("value") -#' ), -#' server = function(input, output, session) { -#' is_dichotomous_slider <- (length(value) == 2) -#' range_value <- toggle_slider_server("toggle_slider", -#' is_dichotomous_slider = is_dichotomous_slider -#' ) -#' messages <- reactiveVal() # to keep history -#' observeEvent(range_value$state(), { -#' list_with_names_str <- function(x) paste(names(x), x, sep = ": ", collapse = ", ") -#' messages(c(messages(), list_with_names_str(range_value$state()))) -#' }) -#' output$value <- renderText({ -#' paste(messages(), collapse = "\n") -#' }) #' -#' # for stress-testing example, update slider settings -#' # bug with invalidateLater not working inside `observeEvent` -#' # observe({ -#' # invalidateLater(1000, session) -#' # a <- sample(0:100, 1) # for range -#' # b <- sample(0:100, 1) -#' # isolate(do.call( -#' # range_value$update_state, -#' # list( -#' # value = sort(sample(0:100, if (is_dichotomous_slider) 2 else 1)), -#' # min = min(a, b), max = max(a, b), -#' # step = sample(1:20, 1) / 10 -#' # )[sample(1:4, sample(4, 1))] # select up to four fields from the list -#' # )) -#' # }) -#' } +#' # use non-exported function from teal.goshawk +#' toggle_slider_ui <- getFromNamespace("toggle_slider_ui", "teal.goshawk") +#' +#' ui <- div( +#' toggle_slider_ui( +#' "toggle_slider", "Select value", +#' min = 0.2, max = 100.1, value = value, +#' slider_initially = FALSE, step_slider = 0.1, step_numeric = 0.001 +#' ), +#' verbatimTextOutput("value") #' ) -#' shinyApp(app$ui, app$server) %>% invisible() +#' +#' server <- function(input, output, session) { +#' is_dichotomous_slider <- (length(value) == 2) +#' range_value <- toggle_slider_server("toggle_slider", +#' is_dichotomous_slider = is_dichotomous_slider +#' ) +#' messages <- reactiveVal() # to keep history +#' observeEvent(range_value$state(), { +#' list_with_names_str <- function(x) paste(names(x), x, sep = ": ", collapse = ", ") +#' messages(c(messages(), list_with_names_str(range_value$state()))) +#' }) +#' output$value <- renderText({ +#' paste(messages(), collapse = "\n") +#' }) +#' } +#' +#' if (interactive()) { +#' shinyApp(ui, server) +#' } toggle_slider_ui <- function(id, label, min, diff --git a/R/utils-maptrt.r b/R/utils-maptrt.r index 9eed7a93..ce9e83a7 100644 --- a/R/utils-maptrt.r +++ b/R/utils-maptrt.r @@ -13,8 +13,7 @@ #' @export #' #' @examples -#' -#' ADSL <- goshawk::rADSL +#' ADSL <- rADSL #' #' # get treatment mapping code #' maptrt(df_armvar = ADSL$ARMCD, code = "M") diff --git a/man/maptrt.Rd b/man/maptrt.Rd index 4c1a1c98..782e4744 100644 --- a/man/maptrt.Rd +++ b/man/maptrt.Rd @@ -21,8 +21,7 @@ mapping and ordering syntax. call the function and then copy and paste the resul into the app.R file. } \examples{ - -ADSL <- goshawk::rADSL +ADSL <- rADSL # get treatment mapping code maptrt(df_armvar = ADSL$ARMCD, code = "M") diff --git a/man/teal_goshawk.Rd b/man/teal.goshawk-package.Rd similarity index 97% rename from man/teal_goshawk.Rd rename to man/teal.goshawk-package.Rd index 2bd13ec8..4e79ffa7 100644 --- a/man/teal_goshawk.Rd +++ b/man/teal.goshawk-package.Rd @@ -1,10 +1,9 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/teal_goshawk.R \docType{package} -\name{teal_goshawk} +\name{teal.goshawk-package} \alias{teal.goshawk} \alias{teal.goshawk-package} -\alias{teal_goshawk} \title{teal.goshawk core packages} \description{ The teal.goshawk package renders the UI and calls the respective biomarker visualization functions. diff --git a/man/tm_g_gh_boxplot.Rd b/man/tm_g_gh_boxplot.Rd index 63a64f2c..8c22d20f 100644 --- a/man/tm_g_gh_boxplot.Rd +++ b/man/tm_g_gh_boxplot.Rd @@ -104,12 +104,15 @@ This teal module renders the UI and calls the functions that create a box plot a summary table. } \examples{ - # Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { library(dplyr) library(nestcolor) + library(stringr) + + # use non-exported function from goshawk + h_identify_loq_values <- getFromNamespace("h_identify_loq_values", "goshawk") # original ARM value = dose value arm_mapping <- list( @@ -118,25 +121,25 @@ data <- within(data, { "C: Combination" = "Combination" ) set.seed(1) - ADSL <- goshawk::rADSL - ADLB <- goshawk::rADLB + ADSL <- rADSL + ADLB <- rADLB var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB \%>\% - dplyr::mutate( - AVISITCD = dplyr::case_when( + mutate( + AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", - grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), + grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), TRUE ~ as.character(NA) ), - AVISITCDN = dplyr::case_when( + AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ as.numeric(NA) ), AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), - TRTORD = dplyr::case_when( + TRTORD = case_when( ARMCD == "ARM C" ~ 1, ARMCD == "ARM B" ~ 2, ARMCD == "ARM A" ~ 3 @@ -148,13 +151,13 @@ data <- within(data, { ANRLO = 50, ANRHI = 75 ) \%>\% - dplyr::rowwise() \%>\% - dplyr::group_by(PARAMCD) \%>\% - dplyr::mutate(LBSTRESC = ifelse( + rowwise() \%>\% + group_by(PARAMCD) \%>\% + mutate(LBSTRESC = ifelse( USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC )) \%>\% - dplyr::mutate(LBSTRESC = ifelse( + mutate(LBSTRESC = ifelse( USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC )) \%>\% @@ -166,8 +169,8 @@ data <- within(data, { attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" # add LLOQ and ULOQ variables - ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB, "LOQFL") - ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM") + ALB_LOQS <- h_identify_loq_values(ADLB, "LOQFL") + ADLB <- left_join(ADLB, ALB_LOQS, by = "PARAM") }) datanames <- c("ADSL", "ADLB") @@ -175,10 +178,10 @@ datanames(data) <- datanames join_keys(data) <- default_cdisc_join_keys[datanames] -app <- teal::init( +app <- init( data = data, - modules = teal::modules( - teal.goshawk::tm_g_gh_boxplot( + modules = modules( + tm_g_gh_boxplot( label = "Box Plot", dataname = "ADLB", param_var = "PARAMCD", diff --git a/man/tm_g_gh_correlationplot.Rd b/man/tm_g_gh_correlationplot.Rd index f426fa13..ae159083 100644 --- a/man/tm_g_gh_correlationplot.Rd +++ b/man/tm_g_gh_correlationplot.Rd @@ -126,10 +126,15 @@ into context. For example the \code{\link[shiny:helpText]{shiny::helpText()}} el Scatter Plot Teal Module For Biomarker Analysis } \examples{ - # Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { + library(dplyr) + library(stringr) + + # use non-exported function from goshawk + h_identify_loq_values <- getFromNamespace("h_identify_loq_values", "goshawk") + # original ARM value = dose value arm_mapping <- list( "A: Drug X" = "150mg QD", @@ -141,11 +146,11 @@ data <- within(data, { shape_manual <- c("N" = 1, "Y" = 2, "NA" = 0) set.seed(1) - ADSL <- goshawk::rADSL - ADLB <- goshawk::rADLB + ADSL <- rADSL + ADLB <- rADLB var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB \%>\% - dplyr::mutate(AVISITCD = dplyr::case_when( + mutate(AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", grepl("WEEK", AVISIT) ~ @@ -155,48 +160,48 @@ data <- within(data, { substr( AVISIT, start = 6, - stop = stringr::str_locate(AVISIT, "DAY") - 1 + stop = str_locate(AVISIT, "DAY") - 1 ) ) ), TRUE ~ NA_character_ )) \%>\% - dplyr::mutate(AVISITCDN = dplyr::case_when( + mutate(AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ NA_real_ )) \%>\% # use ARMCD values to order treatment in visualization legend - dplyr::mutate(TRTORD = ifelse(grepl("C", ARMCD), 1, + mutate(TRTORD = ifelse(grepl("C", ARMCD), 1, ifelse(grepl("B", ARMCD), 2, ifelse(grepl("A", ARMCD), 3, NA) ) )) \%>\% - dplyr::mutate(ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))])) \%>\% - dplyr::mutate(ARM = factor(ARM) \%>\% + mutate(ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))])) \%>\% + mutate(ARM = factor(ARM) \%>\% reorder(TRTORD)) \%>\% - dplyr::mutate( - ANRHI = dplyr::case_when( + mutate( + ANRHI = case_when( PARAMCD == "ALT" ~ 60, PARAMCD == "CRP" ~ 70, PARAMCD == "IGA" ~ 80, TRUE ~ NA_real_ ), - ANRLO = dplyr::case_when( + ANRLO = case_when( PARAMCD == "ALT" ~ 20, PARAMCD == "CRP" ~ 30, PARAMCD == "IGA" ~ 40, TRUE ~ NA_real_ ) ) \%>\% - dplyr::rowwise() \%>\% - dplyr::group_by(PARAMCD) \%>\% - dplyr::mutate(LBSTRESC = ifelse( + rowwise() \%>\% + group_by(PARAMCD) \%>\% + mutate(LBSTRESC = ifelse( USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC )) \%>\% - dplyr::mutate(LBSTRESC = ifelse( + mutate(LBSTRESC = ifelse( USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC )) \%>\% @@ -206,8 +211,8 @@ data <- within(data, { attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" # add LLOQ and ULOQ variables - ADLB_LOQS <- goshawk:::h_identify_loq_values(ADLB, "LOQFL") - ADLB <- dplyr::left_join(ADLB, ADLB_LOQS, by = "PARAM") + ADLB_LOQS <- h_identify_loq_values(ADLB, "LOQFL") + ADLB <- left_join(ADLB, ADLB_LOQS, by = "PARAM") }) datanames <- c("ADSL", "ADLB") @@ -215,10 +220,10 @@ datanames(data) <- datanames join_keys(data) <- default_cdisc_join_keys[datanames] -app <- teal::init( +app <- init( data = data, - modules = teal::modules( - teal.goshawk::tm_g_gh_correlationplot( + modules = modules( + tm_g_gh_correlationplot( label = "Correlation Plot", dataname = "ADLB", param_var = "PARAMCD", @@ -246,7 +251,7 @@ app <- teal::init( hline_arb_color = c("red", "blue"), hline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"), hline_vars_colors = c("green", "blue", "purple", "cyan"), - hline_vars_label = c("ANRHI Label", "ANRLO Label", "ULOQN Label", "LLOQN Label"), + hline_vars_labels = c("ANRHI Label", "ANRLO Label", "ULOQN Label", "LLOQN Label"), vline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"), vline_vars_colors = c("yellow", "orange", "brown", "gold"), vline_vars_labels = c("ANRHI Label", "ANRLO Label", "ULOQN Label", "LLOQN Label"), diff --git a/man/tm_g_gh_density_distribution_plot.Rd b/man/tm_g_gh_density_distribution_plot.Rd index f3a78212..b5338b0c 100644 --- a/man/tm_g_gh_density_distribution_plot.Rd +++ b/man/tm_g_gh_density_distribution_plot.Rd @@ -82,36 +82,37 @@ and an accompanying summary table. None } \examples{ - # Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { library(dplyr) + library(stringr) + # original ARM value = dose value arm_mapping <- list( "A: Drug X" = "150mg QD", "B: Placebo" = "Placebo", "C: Combination" = "Combination" ) - ADSL <- goshawk::rADSL - ADLB <- goshawk::rADLB + ADSL <- rADSL + ADLB <- rADLB var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB \%>\% - dplyr::mutate( - AVISITCD = dplyr::case_when( + mutate( + AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", - grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), + grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), TRUE ~ as.character(NA) ), - AVISITCDN = dplyr::case_when( + AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ as.numeric(NA) ), AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), - TRTORD = dplyr::case_when( + TRTORD = case_when( ARMCD == "ARM C" ~ 1, ARMCD == "ARM B" ~ 2, ARMCD == "ARM A" ~ 3 @@ -130,10 +131,10 @@ datanames <- c("ADSL", "ADLB") datanames(data) <- datanames join_keys(data) <- default_cdisc_join_keys[datanames] -app <- teal::init( +app <- init( data = data, - modules = teal::modules( - teal.goshawk::tm_g_gh_density_distribution_plot( + modules = modules( + tm_g_gh_density_distribution_plot( label = "Density Distribution Plot", dataname = "ADLB", param_var = "PARAMCD", diff --git a/man/tm_g_gh_lineplot.Rd b/man/tm_g_gh_lineplot.Rd index 17a65e88..39155228 100644 --- a/man/tm_g_gh_lineplot.Rd +++ b/man/tm_g_gh_lineplot.Rd @@ -120,7 +120,6 @@ of the relative plot height slider} This teal module renders the UI and calls the function that creates a line plot. } \examples{ - # Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { @@ -135,25 +134,25 @@ data <- within(data, { "C: Combination" = "Combination" ) - ADSL <- goshawk::rADSL - ADLB <- goshawk::rADLB + ADSL <- rADSL + ADLB <- rADLB var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB \%>\% - dplyr::mutate( - AVISITCD = dplyr::case_when( + mutate( + AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", - grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), + grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), TRUE ~ as.character(NA) ), - AVISITCDN = dplyr::case_when( + AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ as.numeric(NA) ), AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), - TRTORD = dplyr::case_when( + TRTORD = case_when( ARMCD == "ARM C" ~ 1, ARMCD == "ARM B" ~ 2, ARMCD == "ARM A" ~ 3 @@ -171,10 +170,10 @@ datanames <- c("ADSL", "ADLB") datanames(data) <- datanames join_keys(data) <- default_cdisc_join_keys[datanames] -app <- teal::init( +app <- init( data = data, - modules = teal::modules( - teal.goshawk::tm_g_gh_lineplot( + modules = modules( + tm_g_gh_lineplot( label = "Line Plot", dataname = "ADLB", param_var = "PARAMCD", diff --git a/man/tm_g_gh_scatterplot.Rd b/man/tm_g_gh_scatterplot.Rd index 3812aaac..e017419a 100644 --- a/man/tm_g_gh_scatterplot.Rd +++ b/man/tm_g_gh_scatterplot.Rd @@ -86,10 +86,12 @@ into context. For example the \code{\link[shiny:helpText]{shiny::helpText()}} el instead. } \examples{ - # Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { + library(dplyr) + library(stringr) + # original ARM value = dose value arm_mapping <- list( "A: Drug X" = "150mg QD", @@ -97,33 +99,33 @@ data <- within(data, { "C: Combination" = "Combination" ) - ADSL <- goshawk::rADSL - ADLB <- goshawk::rADLB + ADSL <- rADSL + ADLB <- rADLB var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB \%>\% - dplyr::mutate( - AVISITCD = dplyr::case_when( + mutate( + AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", - grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), + grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), TRUE ~ as.character(NA) ), - AVISITCDN = dplyr::case_when( + AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ as.numeric(NA) ), - AVISITCD = factor(AVISITCD) \%>\% stats::reorder(AVISITCDN), - TRTORD = dplyr::case_when( + AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), + TRTORD = case_when( ARMCD == "ARM C" ~ 1, ARMCD == "ARM B" ~ 2, ARMCD == "ARM A" ~ 3 ), ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), - ARM = factor(ARM) \%>\% stats::reorder(TRTORD), + ARM = factor(ARM) \%>\% reorder(TRTORD), ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), - ACTARM = factor(ACTARM) \%>\% stats::reorder(TRTORD) + ACTARM = factor(ACTARM) \%>\% reorder(TRTORD) ) attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] @@ -134,10 +136,10 @@ datanames(data) <- datanames join_keys(data) <- default_cdisc_join_keys[datanames] -app <- teal::init( +app <- init( data = data, - modules = teal::modules( - teal.goshawk::tm_g_gh_scatterplot( + modules = modules( + tm_g_gh_scatterplot( label = "Scatter Plot", dataname = "ADLB", param_var = "PARAMCD", diff --git a/man/tm_g_gh_spaghettiplot.Rd b/man/tm_g_gh_spaghettiplot.Rd index be48b465..00bbeef5 100644 --- a/man/tm_g_gh_spaghettiplot.Rd +++ b/man/tm_g_gh_spaghettiplot.Rd @@ -124,11 +124,14 @@ This teal module renders the UI and calls the function that creates a spaghetti plot. } \examples{ - # Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { library(dplyr) + library(stringr) + + # use non-exported function from goshawk + h_identify_loq_values <- getFromNamespace("h_identify_loq_values", "goshawk") # original ARM value = dose value arm_mapping <- list( @@ -137,25 +140,25 @@ data <- within(data, { "C: Combination" = "Combination" ) set.seed(1) - ADSL <- goshawk::rADSL - ADLB <- goshawk::rADLB + ADSL <- rADSL + ADLB <- rADLB var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB \%>\% - dplyr::mutate( - AVISITCD = dplyr::case_when( + mutate( + AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", - grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), + grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), TRUE ~ as.character(NA) ), - AVISITCDN = dplyr::case_when( + AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ as.numeric(NA) ), AVISITCD = factor(AVISITCD) \%>\% reorder(AVISITCDN), - TRTORD = dplyr::case_when( + TRTORD = case_when( ARMCD == "ARM C" ~ 1, ARMCD == "ARM B" ~ 2, ARMCD == "ARM A" ~ 3 @@ -167,12 +170,12 @@ data <- within(data, { ANRLO = 30, ANRHI = 75 ) \%>\% - dplyr::rowwise() \%>\% - dplyr::group_by(PARAMCD) \%>\% - dplyr::mutate(LBSTRESC = ifelse(USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), + rowwise() \%>\% + group_by(PARAMCD) \%>\% + mutate(LBSTRESC = ifelse(USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC )) \%>\% - dplyr::mutate(LBSTRESC = ifelse(USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), + mutate(LBSTRESC = ifelse(USUBJID \%in\% sample(USUBJID, 1, replace = TRUE), paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC )) \%>\% ungroup() @@ -182,18 +185,18 @@ data <- within(data, { attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" # add LLOQ and ULOQ variables - ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB, "LOQFL") - ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM") + ALB_LOQS <- h_identify_loq_values(ADLB, "LOQFL") + ADLB <- left_join(ADLB, ALB_LOQS, by = "PARAM") }) datanames <- c("ADSL", "ADLB") datanames(data) <- datanames join_keys(data) <- default_cdisc_join_keys[datanames] -app <- teal::init( +app <- init( data = data, - modules = teal::modules( - teal.goshawk::tm_g_gh_spaghettiplot( + modules = modules( + tm_g_gh_spaghettiplot( label = "Spaghetti Plot", dataname = "ADLB", param_var = "PARAMCD", diff --git a/man/toggle_slider_ui.Rd b/man/toggle_slider_ui.Rd index 614e7275..4cd99955 100644 --- a/man/toggle_slider_ui.Rd +++ b/man/toggle_slider_ui.Rd @@ -56,46 +56,36 @@ Value is not checked to be within minmax range \examples{ value <- c(20.3, 81.5) # dichotomous slider # value <- c(50.1) # normal slider -app <- shinyApp( - ui = tags$div( - teal.goshawk:::toggle_slider_ui( - "toggle_slider", "Select value", - min = 0.2, max = 100.1, value = value, - slider_initially = FALSE, step_slider = 0.1, step_numeric = 0.001 - ), - verbatimTextOutput("value") - ), - server = function(input, output, session) { - is_dichotomous_slider <- (length(value) == 2) - range_value <- toggle_slider_server("toggle_slider", - is_dichotomous_slider = is_dichotomous_slider - ) - messages <- reactiveVal() # to keep history - observeEvent(range_value$state(), { - list_with_names_str <- function(x) paste(names(x), x, sep = ": ", collapse = ", ") - messages(c(messages(), list_with_names_str(range_value$state()))) - }) - output$value <- renderText({ - paste(messages(), collapse = "\n") - }) - # for stress-testing example, update slider settings - # bug with invalidateLater not working inside `observeEvent` - # observe({ - # invalidateLater(1000, session) - # a <- sample(0:100, 1) # for range - # b <- sample(0:100, 1) - # isolate(do.call( - # range_value$update_state, - # list( - # value = sort(sample(0:100, if (is_dichotomous_slider) 2 else 1)), - # min = min(a, b), max = max(a, b), - # step = sample(1:20, 1) / 10 - # )[sample(1:4, sample(4, 1))] # select up to four fields from the list - # )) - # }) - } +# use non-exported function from teal.goshawk +toggle_slider_ui <- getFromNamespace("toggle_slider_ui", "teal.goshawk") + +ui <- div( + toggle_slider_ui( + "toggle_slider", "Select value", + min = 0.2, max = 100.1, value = value, + slider_initially = FALSE, step_slider = 0.1, step_numeric = 0.001 + ), + verbatimTextOutput("value") ) -shinyApp(app$ui, app$server) \%>\% invisible() + +server <- function(input, output, session) { + is_dichotomous_slider <- (length(value) == 2) + range_value <- toggle_slider_server("toggle_slider", + is_dichotomous_slider = is_dichotomous_slider + ) + messages <- reactiveVal() # to keep history + observeEvent(range_value$state(), { + list_with_names_str <- function(x) paste(names(x), x, sep = ": ", collapse = ", ") + messages(c(messages(), list_with_names_str(range_value$state()))) + }) + output$value <- renderText({ + paste(messages(), collapse = "\n") + }) +} + +if (interactive()) { + shinyApp(ui, server) +} } \keyword{internal}