Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

898 save app state version 3 #262

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
73 changes: 33 additions & 40 deletions R/tm_g_ae_oview.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ tm_g_ae_oview <- function(label,

args <- as.list(environment())

module(
ans <- module(
label = label,
server = srv_g_ae_oview,
server_args = list(
Expand All @@ -118,6 +118,9 @@ tm_g_ae_oview <- function(label,
ui_args = args,
datanames = c("ADSL", dataname)
)
# not bookmarkable: ui_g_decorate cannot be moved to server b/c of args$fontsize
attr(ans, "teal_bookmarkable") <- FALSE
ans
}

ui_g_ae_oview <- function(id, ...) {
Expand All @@ -138,18 +141,7 @@ ui_g_ae_oview <- function(id, ...) {
selected = args$arm_var$selected,
multiple = FALSE
),
selectInput(
ns("arm_ref"),
"Control",
choices = args$arm_var$choices,
selected = args$arm_var$selected
),
selectInput(
ns("arm_trt"),
"Treatment",
choices = args$arm_var$choices,
selected = args$arm_var$selected
),
uiOutput(ns("container_arm")),
selectInput(
ns("flag_var_anl"),
"Flags",
Expand Down Expand Up @@ -209,6 +201,8 @@ srv_g_ae_oview <- function(id,
checkmate::assert_class(isolate(data()), "teal_data")

moduleServer(id, function(input, output, session) {
ns <- session$ns

iv <- reactive({
ANL <- data()[[dataname]]

Expand Down Expand Up @@ -241,11 +235,36 @@ srv_g_ae_oview <- function(id,
font_size <- decorate_output$font_size
pws <- decorate_output$pws

output$container_arm <- renderUI({
req(input$arm_var)

ANL <- data()[[dataname]]
choices <- levels(ANL[[input$arm_var]])

trt_index <- if (length(choices) == 1) 1 else 2

tagList(
selectInput(
ns("arm_ref"),
"Control",
choices = choices,
selected = choices[1L]
),
selectInput(
ns("arm_trt"),
"Treatment",
choices = choices,
selected = choices[trt_index]
)
)
})

observeEvent(list(input$diff_ci_method, input$conf_level), {
req(!is.null(input$diff_ci_method) && !is.null(input$conf_level))
diff_ci_method <- input$diff_ci_method
conf_level <- input$conf_level
updateTextAreaInput(session,
updateTextAreaInput(
session,
"foot",
value = sprintf(
"Note: %d%% CI is calculated using %s",
Expand All @@ -255,32 +274,6 @@ srv_g_ae_oview <- function(id,
)
})

observeEvent(input$arm_var, ignoreNULL = TRUE, {
ANL <- data()[[dataname]]
arm_var <- input$arm_var
arm_val <- ANL[[arm_var]]
choices <- levels(arm_val)

if (length(choices) == 1) {
trt_index <- 1
} else {
trt_index <- 2
}

updateSelectInput(
session,
"arm_ref",
selected = choices[1],
choices = choices
)
updateSelectInput(
session,
"arm_trt",
selected = choices[trt_index],
choices = choices
)
})

output_q <- shiny::debounce(
millis = 200,
r = reactive({
Expand Down
57 changes: 21 additions & 36 deletions R/tm_g_ae_sub.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ tm_g_ae_sub <- function(label,
lower = plot_width[2], upper = plot_width[3], null.ok = TRUE, .var.name = "plot_width"
)

module(
ans <- module(
label = label,
server = srv_g_ae_sub,
server_args = list(
Expand All @@ -93,6 +93,9 @@ tm_g_ae_sub <- function(label,
),
datanames = c("ADSL", dataname)
)
# not bookmarkable: ui_g_decorate cannot be moved to server b/c of args$fontsize
attr(ans, "teal_bookmarkable") <- FALSE
ans
}

ui_g_ae_sub <- function(id, ...) {
Expand All @@ -114,18 +117,7 @@ ui_g_ae_sub <- function(id, ...) {
choices = args$arm_var$choices,
selected = args$arm_var$selected
),
selectInput(
ns("arm_trt"),
"Treatment",
choices = args$arm_var$choices,
selected = args$arm_var$selected
),
selectInput(
ns("arm_ref"),
"Control",
choices = args$arm_var$choices,
selected = args$arm_var$selected
),
uiOutput(ns("arm_container")),
checkboxInput(
ns("arm_n"),
"Show N in each arm",
Expand Down Expand Up @@ -186,6 +178,8 @@ srv_g_ae_sub <- function(id,
checkmate::assert_class(shiny::isolate(data()), "teal_data")

moduleServer(id, function(input, output, session) {
ns <- session$ns

iv <- reactive({
ANL <- data()[[dataname]]
ADSL <- data()[["ADSL"]]
Expand Down Expand Up @@ -223,7 +217,8 @@ srv_g_ae_sub <- function(id,
font_size <- decorate_output$font_size
pws <- decorate_output$pws

observeEvent(input$arm_var, ignoreNULL = TRUE, {
output$arm_container <- renderUI({
req(input$arm_var)
arm_var <- input$arm_var
ANL <- data()[[dataname]]

Expand All @@ -236,17 +231,9 @@ srv_g_ae_sub <- function(id,
ref_index <- 2
}

updateSelectInput(
session,
"arm_trt",
selected = choices[1],
choices = choices
)
updateSelectInput(
session,
"arm_ref",
selected = choices[ref_index],
choices = choices
tagList(
selectInput(ns("arm_trt"), "Treatment", choices = choices, selected = choices[1L]),
selectInput(ns("arm_ref"), "Control", choices = choices, selected = choices[ref_index])
)
})

Expand All @@ -271,34 +258,32 @@ srv_g_ae_sub <- function(id,
observeEvent(input$groups, {
ANL <- data()[[dataname]]
output$grouplabel_output <- renderUI({
grps <- input$groups
grps <- req(input$groups)
lo <- lapply(seq_along(grps), function(index) {
grp <- grps[index]
choices <- levels(ANL[[grp]])
sel <- teal.widgets::optionalSelectInput(
session$ns(sprintf("groups__%s", index)),
ns(sprintf("groups__%s", index)),
grp,
choices,
multiple = TRUE,
selected = choices
)
textname <- sprintf("text_%s_out", index)
txt <- uiOutput(session$ns(textname))
txt <- uiOutput(ns(textname))
observeEvent(
eventExpr = input[[sprintf("groups__%s", index)]],
handlerExpr = {
output[[textname]] <- renderUI({
if (!is.null(input[[sprintf("groups__%s", index)]])) {
l <- input[[sprintf("groups__%s", index)]]
l2 <- lapply(seq_along(l), function(i) {
grps <- req(input[[sprintf("groups__%s", index)]])
if (!is.null(grps)) {
l2 <- lapply(seq_along(grps), function(i) {
nm <- sprintf("groups__%s__level__%s", index, i)
label <- sprintf("Label for %s, Level %s", grp, l[i])
textInput(session$ns(nm), label, l[i])
label <- sprintf("Label for %s, Level %s", grp, grps[i])
textInput(ns(nm), label, grps[i])
})
tagList(textInput(
session$ns(
sprintf("groups__%s__level__%s", index, "all")
),
ns(sprintf("groups__%s__level__%s", index, "all")),
sprintf("Label for %s", grp), grp
), l2)
}
Expand Down
Loading
Loading