Skip to content

Commit

Permalink
allow for reactive expressions inside
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerke committed Jan 8, 2025
1 parent 7df3a26 commit 8ef7ac2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion R/storymaps.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,15 @@ on_section <- function(map_id, section_id, handler) {
# Capture the handler expression
handler_expr <- substitute(handler)

# Create a reactive environment for evaluation
parent_env <- parent.frame()

observeEvent(domain$input[[paste0(map_id, "_active_section")]], {
active_section <- domain$input[[paste0(map_id, "_active_section")]]
if (active_section == section_id) {
eval(handler_expr, envir = parent.frame())
local({
eval(handler_expr, envir = parent_env)
})
}
})
}

0 comments on commit 8ef7ac2

Please sign in to comment.