Skip to content

Commit

Permalink
qenv warnings (#181)
Browse files Browse the repository at this point in the history
Signed-off-by: Dawid Kałędkowski <6959016+gogonzo@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Blazewim <marek.blazewicz@contractors.roche.com>
Co-authored-by: Nikolas Burkoff <nikolas.burkoff@roche.com>
Co-authored-by: Dawid Kałędkowski <dawid.kaledkowski@gmail.com>
Co-authored-by: Dawid Kałędkowski <6959016+gogonzo@users.noreply.github.com>
  • Loading branch information
6 people authored Oct 27, 2022
1 parent f49ca0f commit 7c0dba8
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 24 deletions.
19 changes: 14 additions & 5 deletions R/tm_g_ae_oview.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ ui_g_ae_oview <- function(id, ...) {
footnotes = ""
)
),
forms = teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
forms = tagList(
teal.widgets::verbatim_popup_ui(ns("warning"), "Show Warnings"),
teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
)
)
}

Expand Down Expand Up @@ -294,13 +297,12 @@ srv_g_ae_oview <- function(id,
input$arm_trt,
message_fmt = "Must not be equal to Treatment"
))

iv_comp$enable()
validate(need(iv_comp$is_valid(), "Misspecification error: please observe red flags in the encodings."))

validate(need(iv_comp$is_valid(), "Misspecification error: please observe red flags in the encodings."))
validate(need(nlevels(ANL[[input$arm_var]]) > 1, "Arm needs to have at least 2 levels"))
validate_has_data(ANL, min_nrow = 10)
if (all(c(input$arm_trt, input$arm_ref) %in% ANL_UNFILTERED[[input$arm_var]])) {
if (all(c(input$arm_trt, input$arm_ref) %in% ANL[[input$arm_var]])) {
iv_an <- shinyvalidate::InputValidator$new()
iv_an$add_rule("arm_ref", shinyvalidate::sv_in_set(set = ANL[[input$arm_var]]))
iv_an$add_rule("arm_trt", shinyvalidate::sv_in_set(set = ANL[[input$arm_var]]))
Expand All @@ -310,7 +312,7 @@ srv_g_ae_oview <- function(id,
validate(need(all(c(input$arm_trt, input$arm_ref) %in% unique(ANL[[input$arm_var]])), "Plot loading"))

q1 <- teal.code::eval_code(
teal.code::new_qenv(tdata2env(data), code = get_code(data)),
teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data)),
code = as.expression(c(
bquote(anl_labels <- formatters::var_labels(.(as.name(dataname)), fill = FALSE)),
bquote(flags <- .(as.name(dataname)) %>%
Expand Down Expand Up @@ -344,6 +346,13 @@ srv_g_ae_oview <- function(id,

plot_r <- reactive(output_q()[["plot"]])

teal.widgets::verbatim_popup_srv(
id = "warning",
verbatim_content = reactive(teal.code::get_warnings(output_q())),
title = "Warning",
disabled = reactive(is.null(teal.code::get_warnings(output_q())))
)

teal.widgets::verbatim_popup_srv(
id = "rcode",
verbatim_content = reactive(teal.code::get_code(output_q())),
Expand Down
14 changes: 12 additions & 2 deletions R/tm_g_ae_sub.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ ui_g_ae_sub <- function(id, ...) {
)
)
),
forms = teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
forms = tagList(
teal.widgets::verbatim_popup_ui(ns("warning"), "Show Warnings"),
teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
)
)
}

Expand Down Expand Up @@ -336,7 +339,7 @@ srv_g_ae_sub <- function(id,
bquote(group_labels <- setNames(.(group_labels), .(input$groups)))
}

q1 <- teal.code::eval_code(teal.code::new_qenv(tdata2env(data), code = get_code(data)), code = group_labels_call)
q1 <- teal.code::eval_code(teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data)), code = group_labels_call)
q2 <- teal.code::eval_code(q1, code = "")
teal.code::eval_code(
q2,
Expand Down Expand Up @@ -365,6 +368,13 @@ srv_g_ae_sub <- function(id,

plot_r <- reactive(output_q()[["plot"]])

teal.widgets::verbatim_popup_srv(
id = "warning",
verbatim_content = reactive(teal.code::get_warnings(output_q())),
title = "Warning",
disabled = reactive(is.null(teal.code::get_warnings(output_q())))
)

teal.widgets::verbatim_popup_srv(
id = "rcode",
verbatim_content = reactive(teal.code::get_code(output_q())),
Expand Down
14 changes: 12 additions & 2 deletions R/tm_g_butterfly.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ ui_g_butterfly <- function(id, ...) {
value = a$legend_on
)
),
forms = teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code"),
forms = tagList(
teal.widgets::verbatim_popup_ui(ns("warning"), "Show Warnings"),
teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
),
pre_output = a$pre_output,
post_output = a$post_output
)
Expand Down Expand Up @@ -407,7 +410,7 @@ srv_g_butterfly <- function(id, data, filter_panel_api, reporter, dataname, labe
anl_vars <- unique(c("USUBJID", "STUDYID", varlist_from_anl)) # nolint

q1 <- teal.code::eval_code(
teal.code::new_qenv(tdata2env(data), code = get_code(data)),
teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data)),
code = bquote({
ADSL <- ADSL[, .(adsl_vars)] %>% as.data.frame() # nolint
ANL <- .(as.name(dataname))[, .(anl_vars)] %>% as.data.frame() # nolint
Expand Down Expand Up @@ -489,6 +492,13 @@ srv_g_butterfly <- function(id, data, filter_panel_api, reporter, dataname, labe
width = plot_width
)

teal.widgets::verbatim_popup_srv(
id = "warning",
verbatim_content = reactive(teal.code::get_warnings(output_q())),
title = "Warning",
disabled = reactive(is.null(teal.code::get_warnings(output_q())))
)

teal.widgets::verbatim_popup_srv(
id = "rcode",
title = paste("R code for", label),
Expand Down
14 changes: 12 additions & 2 deletions R/tm_g_events_term_id.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ ui_g_events_term_id <- function(id, ...) {
footnotes = ""
)
),
forms = teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
forms = tagList(
teal.widgets::verbatim_popup_ui(ns("warning"), "Show Warnings"),
teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
)
)
}

Expand Down Expand Up @@ -315,7 +318,7 @@ srv_g_events_term_id <- function(id,
anl_vars <- c("USUBJID", "STUDYID", input$term) # nolint

q1 <- teal.code::eval_code(
teal.code::new_qenv(tdata2env(data), code = get_code(data)),
teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data)),
code = bquote(
ANL <- merge( # nolint
x = ADSL[, .(adsl_vars), drop = FALSE],
Expand Down Expand Up @@ -357,6 +360,13 @@ srv_g_events_term_id <- function(id,

plot_r <- reactive(output_q()[["plot"]])

teal.widgets::verbatim_popup_srv(
id = "warning",
verbatim_content = reactive(teal.code::get_warnings(output_q())),
title = "Warning",
disabled = reactive(is.null(teal.code::get_warnings(output_q())))
)

teal.widgets::verbatim_popup_srv(
id = "rcode",
title = paste("R code for", label),
Expand Down
18 changes: 14 additions & 4 deletions R/tm_g_heat_bygrade.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ ui_g_heatmap_bygrade <- function(id, ...) {
footnotes = ""
)
),
forms = teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
forms = tagList(
teal.widgets::verbatim_popup_ui(ns("warning"), "Show Warnings"),
teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
)
)
)
}
Expand Down Expand Up @@ -377,7 +380,7 @@ srv_g_heatmap_bygrade <- function(id,
paste("Please de-select", input$id_var, "in annotation variable(s)", sep = " ")
))

if (input$plot_cm) {
if (isTRUE(input$plot_cm)) {
ADCM <- data[[cm_dataname]]() # nolint
validate(
need(
Expand All @@ -395,15 +398,15 @@ srv_g_heatmap_bygrade <- function(id,
))
}

q1 <- if (input$plot_cm) {
q1 <- if (isTRUE(input$plot_cm)) {
iv_cm <- shinyvalidate::InputValidator$new()
conmed_var <- input$conmed_var
iv_cm$add_rule("conmed_var", shinyvalidate::sv_required())
iv_cm$enable()
validate(need(iv_cm$is_valid(), "Misspecification error: please observe red flags in the encodings."))

teal.code::eval_code(
teal.code::new_qenv(tdata2env(data), code = get_code(data)),
teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data)),
code = bquote({
conmed_data <- ADCM %>%
filter(!!sym(.(conmed_var)) %in% .(input$conmed_level))
Expand Down Expand Up @@ -447,6 +450,13 @@ srv_g_heatmap_bygrade <- function(id,

plot_r <- reactive(output_q()[["plot"]])

teal.widgets::verbatim_popup_srv(
id = "warning",
verbatim_content = reactive(teal.code::get_warnings(output_q())),
title = "Warning",
disabled = reactive(is.null(teal.code::get_warnings(output_q())))
)

teal.widgets::verbatim_popup_srv(
id = "rcode",
title = paste("R code for", label),
Expand Down
17 changes: 14 additions & 3 deletions R/tm_g_patient_profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,10 @@ ui_g_patient_profile <- function(id, ...) {
value = a$x_limit
)
),
forms = teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code"),
forms = tagList(
teal.widgets::verbatim_popup_ui(ns("warning"), "Show Warnings"),
teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
),
pre_output = a$pre_output,
post_output = a$post_output
)
Expand Down Expand Up @@ -632,9 +635,10 @@ srv_g_patient_profile <- function(id,
lb_dataname
)
input_select <- purrr::map_lgl(datanames, is.na)

select_plot <- purrr::map2_lgl(
input_select, possible_plot,
~ if (!.x) {
~ if (!.x && paste("select", .y, sep = "_") %in% names(input)) {
input[[paste("select", .y, sep = "_")]]
} else {
FALSE
Expand All @@ -650,7 +654,7 @@ srv_g_patient_profile <- function(id,
empty_lb <- FALSE

q1 <- teal.code::eval_code(
teal.code::new_qenv(tdata2env(data), code = get_code(data)),
teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data)),
code = bquote({
ADSL <- ADSL %>% # nolint
group_by(.data$USUBJID)
Expand Down Expand Up @@ -1068,6 +1072,13 @@ srv_g_patient_profile <- function(id,
width = plot_width
)

teal.widgets::verbatim_popup_srv(
id = "warning",
verbatim_content = reactive(teal.code::get_warnings(output_q())),
title = "Warning",
disabled = reactive(is.null(teal.code::get_warnings(output_q())))
)

teal.widgets::verbatim_popup_srv(
id = "rcode",
title = paste("R code for", label),
Expand Down
14 changes: 12 additions & 2 deletions R/tm_g_spiderplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ ui_g_spider <- function(id, ...) {
value = a$href_line
)
),
forms = teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code"),
forms = tagList(
teal.widgets::verbatim_popup_ui(ns("warning"), "Show Warnings"),
teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
),
pre_output = a$pre_output,
post_output = a$post_output
)
Expand Down Expand Up @@ -271,7 +274,7 @@ srv_g_spider <- function(id, data, filter_panel_api, reporter, dataname, label,

# merge
q1 <- teal.code::eval_code(
teal.code::new_qenv(tdata2env(data), code = get_code(data)),
teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data)),
code = bquote({
ADSL <- ADSL[, .(adsl_vars)] %>% as.data.frame() # nolint
ADTR <- .(as.name(dataname))[, .(adtr_vars)] %>% as.data.frame() # nolint
Expand Down Expand Up @@ -379,6 +382,13 @@ srv_g_spider <- function(id, data, filter_panel_api, reporter, dataname, label,
width = plot_width
)

teal.widgets::verbatim_popup_srv(
id = "warning",
verbatim_content = reactive(teal.code::get_warnings(output_q())),
title = "Warning",
disabled = reactive(is.null(teal.code::get_warnings(output_q())))
)

teal.widgets::verbatim_popup_srv(
id = "rcode",
title = paste("R code for", label),
Expand Down
14 changes: 12 additions & 2 deletions R/tm_g_swimlane.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ ui_g_swimlane <- function(id, ...) {
value = paste(a$vref_line, collapse = ", ")
)
),
forms = teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code"),
forms = tagList(
teal.widgets::verbatim_popup_ui(ns("warning"), "Show Warnings"),
teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
),
pre_output = a$pre_output,
post_output = a$post_output
)
Expand Down Expand Up @@ -316,7 +319,7 @@ srv_g_swimlane <- function(id,

ADSL <- data[["ADSL"]]() # nolint

q1 <- teal.code::new_qenv(tdata2env(data), code = get_code(data))
q1 <- teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data))

# VARIABLE GETTERS
# lookup bar variables
Expand Down Expand Up @@ -513,6 +516,13 @@ srv_g_swimlane <- function(id,
width = plot_width
)

teal.widgets::verbatim_popup_srv(
id = "warning",
verbatim_content = reactive(teal.code::get_warnings(output_q())),
title = "Warning",
disabled = reactive(is.null(teal.code::get_warnings(output_q())))
)

teal.widgets::verbatim_popup_srv(
id = "rcode",
title = paste("R code for", label),
Expand Down
14 changes: 12 additions & 2 deletions R/tm_g_waterfall.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ ui_g_waterfall <- function(id, ...) {
value = a$gap_point_val
)
),
forms = teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code"),
forms = tagList(
teal.widgets::verbatim_popup_ui(ns("warning"), "Show Warnings"),
teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
),
pre_output = a$pre_output,
post_output = a$post_output
)
Expand Down Expand Up @@ -388,7 +391,7 @@ srv_g_waterfall <- function(id,

# write variables to qenv
q1 <- teal.code::eval_code(
teal.code::new_qenv(tdata2env(data), code = get_code(data)),
teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data)),
code = bquote({
bar_var <- .(bar_var)
bar_color_var <- .(bar_color_var)
Expand Down Expand Up @@ -521,6 +524,13 @@ srv_g_waterfall <- function(id,
width = plot_width
)

teal.widgets::verbatim_popup_srv(
id = "warning",
verbatim_content = reactive(teal.code::get_warnings(output_q())),
title = "Warning",
disabled = reactive(is.null(teal.code::get_warnings(output_q())))
)

# Show R Code
teal.widgets::verbatim_popup_srv(
id = "rcode",
Expand Down

0 comments on commit 7c0dba8

Please sign in to comment.