Skip to content

Commit

Permalink
Add option to remove interval in tm_g_lineplot (#840)
Browse files Browse the repository at this point in the history
Closes #350
  • Loading branch information
edelarua authored Oct 27, 2023
1 parent 51d521c commit 323fc0e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 22 additions & 14 deletions R/tm_g_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -432,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"),
Expand Down Expand Up @@ -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)
})

Expand Down Expand Up @@ -597,9 +599,15 @@ 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)
if (is.null(input$interval) || is.null(whiskers_selected)) {
input_whiskers <- NULL
input_interval <- NULL
} else {
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]]]))

my_calls <- template_g_lineplot(
Expand Down
10 changes: 6 additions & 4 deletions man/template_g_lineplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions man/tm_g_lineplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 323fc0e

Please sign in to comment.