Skip to content
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
993babd
Add numericRangeInput widget for x and y axes
luffmark Apr 23, 2025
afa93b5
Remove commented code
luffmark Apr 23, 2025
1ea37fa
Add test for x and y axes ranges
luffmark Apr 24, 2025
d041303
Use all_of() and fix mod_edish test
luffmark Apr 24, 2025
0613c7f
Update range id lookup
luffmark Apr 24, 2025
e1ed7b6
Fix issue with range id ref, and update upper limit of axes
luffmark Apr 25, 2025
4d709ed
Fix issues with 05-mod_edish test
luffmark Apr 28, 2025
184f78b
Fix snapshot
luffmark Apr 28, 2025
6972dd1
Fix comment in code
luffmark Apr 28, 2025
e613173
Update bookmarking test
luffmark Apr 28, 2025
19761c5
Add ranges to bookmark test
luffmark Apr 28, 2025
ae677e7
Update bookmarking test
luffmark Apr 29, 2025
a21dc28
Modify range in bookmarking test
luffmark Apr 29, 2025
011b631
Try to fix failing bookmarking test
luffmark Apr 29, 2025
571d038
Try to fix bookmarking test
luffmark Apr 29, 2025
82f02f7
Update handling of x- and y-axis ranges
luffmark May 2, 2025
a3f76bc
Update tests
luffmark May 2, 2025
936f325
Fix snapshot
luffmark May 2, 2025
c49bc75
Debugging test
luffmark May 2, 2025
b557b98
Debug test
luffmark May 2, 2025
1e223e1
debug
luffmark May 2, 2025
e320a89
debug
luffmark May 2, 2025
f03f774
debug
luffmark May 2, 2025
aa2e10b
debug
luffmark May 2, 2025
a630678
Update header of function
luffmark May 2, 2025
bc18d57
fix range testing
zsigmas May 5, 2025
205e200
Update test
luffmark May 5, 2025
258005e
Set x_ref as decimal to avoid type mismatch
luffmark May 5, 2025
83ae910
Address review comment - change point to limit in comment
luffmark May 6, 2025
c32864f
Update documentation
luffmark May 6, 2025
3502d64
Fix range widget label
luffmark May 6, 2025
1b2171c
Update screenshot for README.md
luffmark May 7, 2025
edfaa53
Build documentation
luffmark May 8, 2025
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
50 changes: 43 additions & 7 deletions R/helper_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ filter_data <- function(dataset, arm_var, sel_arm, lb_test_var, sel_lb_test) {
#'
#' @param dataset `[data.frame]`
#'
#' A dataframe containing the variables listed below as columns.
#' A data frame containing the variables listed below as columns.
#' @param subjectid_var `[character(1)]`
#'
#' Name of the variable containing the unique subject IDs.
Expand Down Expand Up @@ -175,7 +175,7 @@ derive_req_vars <- function(
return(NULL)
}

# Get the data-frame in required structure (Pivot wider grouped by certain variables)
# Get the data frame in required structure (Pivot wider grouped by certain variables)
dataset <- dataset %>%
dplyr::filter(.data[[lb_test_var]] %in% c(sel_x, sel_y)) %>%
dplyr::mutate(
Expand All @@ -185,7 +185,7 @@ derive_req_vars <- function(
dplyr::select(dplyr::all_of(c(subjectid_var, arm_var, lb_test_var, visit_var, "r_ULN", "r_Baseline"))) %>%
dplyr::group_by(.data[[subjectid_var]], .data[[arm_var]], .data[[lb_test_var]], .data[[visit_var]]) %>%
dplyr::mutate(row = dplyr::row_number()) %>%
tidyr::pivot_wider(names_from = lb_test_var, values_from = c("r_ULN", "r_Baseline")) %>%
tidyr::pivot_wider(names_from = tidyr::all_of(lb_test_var), values_from = c("r_ULN", "r_Baseline")) %>%
dplyr::select(-dplyr::all_of("row")) %>%
dplyr::mutate(
"r_ULN_{{sel_x}}" = as.numeric(.data[[paste0("r_ULN_", sel_x)]]),
Expand All @@ -205,7 +205,7 @@ derive_req_vars <- function(
#'
#' @param dataset `[data.frame]`
#'
#' A dataframe containing the variables listed below as columns.
#' A data frame containing the variables listed below as columns.
#' @param subjectid_var `[character(1)]`
#'
#' Name of the variable containing the unique subject IDs.
Expand All @@ -229,6 +229,24 @@ derive_req_vars <- function(
#'
#' Character specifying the plot type for the y-axis. This leads to
#' using the `dataset`'s column "r_<y_plot_type>_<y_sel>" for the y-values.
#' @param x_ref_line_num `[numeric(1)]`
#'
#' Numeric specifying the reference line for the x-axis.
#' @param y_ref_line_num `[numeric(1)]`
#'
#' Numeric specifying the reference line for the y-axis.
#' @param x_rng_lower `[numeric(1)]`
#'
#' Numeric specifying the lower point in the x-axis range.
#' @param x_rng_upper `[numeric(1)]`
#'
#' Numeric specifying the upper point in the x-axis range.
#' @param y_rng_lower `[numeric(1)]`
#'
#' Numeric specifying the lower point in the y-axis range.
#' @param y_rng_upper `[numeric(1)]`
#'
#' Numeric specifying the upper point in the y-axis range.
#'
Comment thread
luffmark marked this conversation as resolved.
#' @return A plotly object specifying the generated eDISH plot.
#'
Expand All @@ -243,11 +261,29 @@ generate_plot <- function(
x_plot_type,
y_plot_type,
x_ref_line_num,
y_ref_line_num) {
y_ref_line_num,
x_rng_lower,
x_rng_upper,
y_rng_lower,
y_rng_upper) {
if (is.null(dataset)) {
return(dataset)
}

# Prepare x-axis layout based on whether range has been specified
layout_xaxis <- list(title = paste0(sel_x, "/", x_plot_type))
if (!is.null(x_rng_lower) && !is.null(x_rng_upper)) {
layout_xaxis <- c(layout_xaxis,
list(range = c(x_rng_lower, x_rng_upper)))
}

# Prepare y-axis layout based on whether range has been specified
layout_yaxis <- list(title = paste0(sel_y, "/", y_plot_type))
if (!is.null(y_rng_lower) && !is.null(y_rng_upper)) {
layout_yaxis <- c(layout_yaxis,
list(range = c(y_rng_lower, y_rng_upper)))
}

Comment thread
luffmark marked this conversation as resolved.
plt_obj <- dataset %>%
plotly::plot_ly(type = "scatter", mode = "markers", color = .[[arm_var]]) %>%
plotly::add_trace(
Expand All @@ -263,8 +299,8 @@ generate_plot <- function(
hoverinfo = "text"
) %>%
plotly::layout(
xaxis = list(title = paste0(sel_x, "/", x_plot_type)),
yaxis = list(title = paste0(sel_y, "/", y_plot_type)),
xaxis = layout_xaxis,
yaxis = layout_yaxis,
shapes = list(
list( # vline
type = "line",
Expand Down
29 changes: 25 additions & 4 deletions R/mod_edish.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ EDISH <- pack_of_constants(
AXIS_LABEL = "Parameter:",
X_REF_ID = "x_ref",
Y_REF_ID = "y_ref",
X_RNG_ID = "x_rng",
Y_RNG_ID = "y_rng",
REF_LABEL = "Reference line:",
X_PLOT_TYPE_ID = "x_plot_type",
Y_PLOT_TYPE_ID = "y_plot_type",
PLOT_TYPE_CHOICES = c("x ULN (eDISH)", "x Baseline (mDISH)"),
PLOT_TYPE_CHOICES = c("\u00d7 ULN (eDISH)" = "ULN",
"\u00d7 Baseline (mDISH)" = "Baseline"),
PLOT_ID = "plot",
NO_PLOT = "noplot"
)
Expand Down Expand Up @@ -59,6 +62,14 @@ edish_UI <- function(module_id) {
max = 100,
step = 0.5
),
shinyWidgets::numericRangeInput(
inputId = ns(EDISH$X_RNG_ID),
label = "Range",
value = c(NA, NA),
min = 0,
max = 100,
step = 0.1
),
shiny::radioButtons(
inputId = ns(EDISH$X_PLOT_TYPE_ID),
label = NULL,
Expand All @@ -79,6 +90,14 @@ edish_UI <- function(module_id) {
max = 100,
step = 0.5
),
shinyWidgets::numericRangeInput(
inputId = ns(EDISH$Y_RNG_ID),
label = "Range",
Comment thread
luffmark marked this conversation as resolved.
Outdated
value = c(NA, NA),
min = 0,
max = 100,
step = 0.1
),
shiny::radioButtons(
inputId = ns(EDISH$Y_PLOT_TYPE_ID),
label = NULL,
Expand Down Expand Up @@ -269,9 +288,11 @@ edish_server <- function(
dataset = plot_data(),
subjectid_var = subjectid_var, arm_var = arm_var, visit_var = visit_var,
sel_x = input[[EDISH$X_AXIS_ID]], sel_y = input[[EDISH$Y_AXIS_ID]],
x_plot_type = ifelse(grepl("eDISH", input[[EDISH$X_PLOT_TYPE_ID]]), "ULN", "Baseline"),
y_plot_type = ifelse(grepl("eDISH", input[[EDISH$Y_PLOT_TYPE_ID]]), "ULN", "Baseline"),
x_ref_line_num = input[[EDISH$X_REF_ID]], y_ref_line_num = input[[EDISH$Y_REF_ID]]
x_plot_type = input[[EDISH$X_PLOT_TYPE_ID]],
y_plot_type = input[[EDISH$Y_PLOT_TYPE_ID]],
x_ref_line_num = input[[EDISH$X_REF_ID]], y_ref_line_num = input[[EDISH$Y_REF_ID]],
x_rng_lower = input[[EDISH$X_RNG_ID]][1], x_rng_upper = input[[EDISH$X_RNG_ID]][2],
y_rng_lower = input[[EDISH$Y_RNG_ID]][1], y_rng_upper = input[[EDISH$Y_RNG_ID]][2]
)
)

Expand Down
10 changes: 8 additions & 2 deletions tests/testthat/_snaps/05-mod_edish.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,26 @@
[1] "test 1"

$input$`edish-x_plot_type`
[1] "x ULN (eDISH)"
[1] "ULN"

$input$`edish-x_ref`
[1] 3

$input$`edish-x_rng`
NULL

$input$`edish-y_axis`
[1] "test 2"

$input$`edish-y_plot_type`
[1] "x ULN (eDISH)"
[1] "ULN"

$input$`edish-y_ref`
[1] 2

$input$`edish-y_rng`
NULL

$input$`plotly_afterplot-A`
[1] "\"edish-plot\""

Expand Down
22 changes: 21 additions & 1 deletion tests/testthat/test-04-generate_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ x_plot_type <- "ULN"
y_plot_type <- "Baseline"
x_ref_line_num <- 3
y_ref_line_num <- 2
x_rng_lower <- 0
x_rng_upper <- 10
y_rng_lower <- 0
y_rng_upper <- 10

# Invoke the function
plt_obj <- generate_plot(
Expand All @@ -60,7 +64,11 @@ plt_obj <- generate_plot(
x_plot_type = x_plot_type,
y_plot_type = y_plot_type,
x_ref_line_num = x_ref_line_num,
y_ref_line_num = y_ref_line_num
y_ref_line_num = y_ref_line_num,
x_rng_lower = x_rng_lower,
x_rng_upper = x_rng_upper,
y_rng_lower = y_rng_lower,
y_rng_upper = y_rng_upper
)

# Tests
Expand Down Expand Up @@ -110,6 +118,18 @@ test_that("the resulting plot object includes the correct reference lines" %>%
expect_identical(actual_y1, y_ref_line_num)
})

test_that("the resulting plot object includes the correct axis range" %>%
vdoc[["add_spec"]](specs$plot_specs$axis_labels), {
actual_x <- plt_obj$x$layoutAttrs[[1]]$xaxis$range
actual_y <- plt_obj$x$layoutAttrs[[1]]$yaxis$range

expected_x <- c(x_rng_lower, x_rng_upper)
expected_y <- c(y_rng_lower, y_rng_upper)

expect_identical(actual_x, expected_x)
expect_identical(actual_y, expected_y)
})

test_that("the resulting plot object includes the correct coloring" %>%
vdoc[["add_spec"]](specs$plot_specs$arm_coloring), {
actual <- plt_obj$x$attrs[[1]]$color
Expand Down
37 changes: 26 additions & 11 deletions tests/testthat/test-05-mod_edish.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test_that("the app displays the correct plot at app launch (snapshot test)" %>%
app$stop()
})

test_that("default settigns are visible after Single-Sign-On redirect", {
test_that("default settings are visible after Single-Sign-On redirect", {
skip("Cannot integrate SSO within unit tests, i.e., this test has to be performed manually.")
})

Expand All @@ -56,33 +56,48 @@ test_that("the app's state is restored when bookmarking" %>%
app_bmk <- shinytest2::AppDriver$new(
app_dir = "./apps/bookmarking_app", name = "test_bookmarking"
)

app$wait_for_idle()
app_bmk$wait_for_idle()

# Update values
app_bmk$set_inputs(`edish-arm_id` = c("arm1", "arm2"))
app_bmk$set_inputs(`edish-x_axis` = "test 2")
app_bmk$set_inputs(`edish-x_ref` = 3)
app_bmk$set_inputs(`edish-x_plot_type` = "x Baseline (mDISH)")
app_bmk$set_inputs(`edish-x_ref` = 3.5)
app_bmk$set_inputs(`edish-x_plot_type` = "Baseline")

# It is not possible to set shinyWidgets::numericalRangeInput using shinytest2
# We use an alternative approach by setting the url query part manually
# nolint start
# app_bmk$set_inputs(`edish-x_rng` = c(0.1, 5.1))
# app_bmk$set_inputs(`edish-y_rng` = c(0.1, 7.1))
# nolint end
range_url_part <- "&edish-x_rng=%5B0.1%2C5.1%5D&edish-y_rng=%5B0.1%2C7.1%5D"

# Bookmark
app_bmk$set_inputs(!!"._bookmark_" := "click") # nolint

# Initialize bookmarked app
bmk_url <- app_bmk$get_value(export = "url")
app_rst <- shinytest2::AppDriver$new(app_dir = bmk_url, name = "test_restoring")
bmk_url <- app_bmk$get_value(export = "url")

bmk_url_with_range <- paste0(bmk_url, range_url_part)
app_rst <- shinytest2::AppDriver$new(app_dir = bmk_url_with_range, name = "test_restoring")

app_rst$wait_for_idle()

# Get values and test
actual <- app_rst$get_values(input = c("edish-arm_id", "edish-x_axis", "edish-x_plot_type", "edish-x_ref"))
actual <- app_rst$get_values(input = c("edish-arm_id", "edish-x_axis", "edish-x_plot_type", "edish-x_ref",
"edish-x_rng", "edish-y_rng"))
expected <- list(
input = list(
`edish-arm_id` = c("arm1", "arm2"),
`edish-x_axis` = "test 2",
`edish-x_plot_type` = "x Baseline (mDISH)",
`edish-x_ref` = 3
`edish-x_plot_type` = "Baseline",
`edish-x_ref` = 3.5,
`edish-x_rng` = c(0.1, 5.1),
`edish-y_rng` = c(0.1, 7.1)
)
)
testthat::expect_equal(actual, expected)
testthat::expect_identical(actual, expected)

# Stop apps
app_bmk$stop()
Expand Down
Loading