Skip to content

Commit

Permalink
Merge pull request #2038 from rstudio/joe/bugfix/cycle-start-bugs
Browse files Browse the repository at this point in the history
Fix #2037: With enableBookmarking="url", clientData is not available …
  • Loading branch information
wch authored Apr 25, 2018
2 parents c2f03aa + 9dd4302 commit 01b24e9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
15 changes: 9 additions & 6 deletions R/reactives.R
Original file line number Diff line number Diff line change
Expand Up @@ -1401,12 +1401,15 @@ reactiveTimer <- function(intervalMs=1000, session = getDefaultReactiveDomain())
}

timerHandle <<- scheduleTask(intervalMs, sys.function())
lapply(
dependents$values(),
function(dep.ctx) {
dep.ctx$invalidate()
NULL
})

session$cycleStartAction(function() {
lapply(
dependents$values(),
function(dep.ctx) {
dep.ctx$invalidate()
NULL
})
})
})

if (!is.null(session)) {
Expand Down
14 changes: 13 additions & 1 deletion R/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,19 @@ createAppHandlers <- function(httpHandlers, serverFuncSource) {
shinysession$setShowcase(mode)
}

shinysession$manageInputs(msg$data)
# In shinysession$createBookmarkObservers() above, observers may be
# created, which puts the shiny session in busyCount > 0 state. That
# prevents the manageInputs here from taking immediate effect, by
# default. The manageInputs here needs to take effect though, because
# otherwise the bookmark observers won't find the clientData they are
# looking for. So use `now = TRUE` to force the changes to be
# immediate.
#
# FIXME: break createBookmarkObservers into two separate steps, one
# before and one after manageInputs, and put the observer creation
# in the latter. Then add an assertion that busyCount == 0L when
# this manageInputs is called.
shinysession$manageInputs(msg$data, now = TRUE)

# The client tells us what singletons were rendered into
# the initial page
Expand Down
19 changes: 15 additions & 4 deletions R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -1863,10 +1863,16 @@ ShinySession <- R6Class(
}
}
},
# Set the normal and client data input variables
manageInputs = function(data) {
# Set the normal and client data input variables. Normally, managing
# inputs doesn't take immediate effect when there are observers that
# are pending execution or currently executing (including having
# started async operations that have yielded control, but not yet
# completed). The `now` argument can force this. It should generally
# not be used, but we're adding it to get around a show-stopping bug
# for Shiny v1.1 (see the call site for more details).
manageInputs = function(data, now = FALSE) {
force(data)
self$cycleStartAction(function() {
doManageInputs <- function() {
private$inputReceivedCallbacks$invoke(data)

data_names <- names(data)
Expand All @@ -1884,7 +1890,12 @@ ShinySession <- R6Class(
private$.clientData$mset(input_clientdata)

self$manageHiddenOutputs()
})
}
if (isTRUE(now)) {
doManageInputs()
} else {
self$cycleStartAction(doManageInputs)
}
},
outputOptions = function(name, ...) {
# If no name supplied, return the list of options for all outputs
Expand Down

0 comments on commit 01b24e9

Please sign in to comment.