Skip to content

Commit

Permalink
Enable $isActive() in modules, v2
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Jul 22, 2024
1 parent 5403e1d commit 8780cd2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
19 changes: 16 additions & 3 deletions R/conductor.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Conductor <- R6::R6Class(
defaultStepOptions = NULL, mathjax = FALSE,
progress = FALSE, onComplete = NULL, onCancel = NULL,
onHide = NULL, onShow = NULL, onStart = NULL,
onActive = NULL, onInactive = NULL) {
onActive = NULL, onInactive = NULL, id = NULL) {

private$globals <- list(
exitOnEsc = exitOnEsc,
Expand Down Expand Up @@ -126,6 +126,10 @@ Conductor <- R6::R6Class(
)
}

if (!is.null(id)) {
private$id <- id
}

private$mathjax <- mathjax
invisible(self)
},
Expand Down Expand Up @@ -671,8 +675,17 @@ Conductor <- R6::R6Class(
isActive = function(session = NULL) {
if(is.null(session)) {
session <- shiny::getDefaultReactiveDomain()
}
session$input[[paste0(private$id, "_is_active")]]
} else {
# If we pass a module session, then the id was wrapped in ns() so that
# the module detects it. However, it means that I have to remove the
# module prefix before session$input[[<id>]] since [[.reactivevalues
# already takes care of adding a prefix.
#
# I don't think I have a way to get the prefix from the session$input
# object so I remove everything before the first dash.
id <- gsub(".*-", "", private$id)
}
session$input[[paste0(id, "_is_active")]]
}
)
)
3 changes: 1 addition & 2 deletions inst/packer/conductor.js

Large diffs are not rendered by default.

0 comments on commit 8780cd2

Please sign in to comment.