mirror of
https://github.com/rstudio/shiny.git
synced 2026-02-05 12:15:14 -05:00
These functions were created before getDefaultReactiveDomain() existed, so the only way to get ahold of the current session was if the caller explicitly passed it. This is slightly backwards incompatible, in that existing calls to invalidateLater() that don't pass a session argument will behave slightly differently (bound to the current session instead of to no session), but those calls would have triggered a warning for all but the very earliest versions of Shiny.
58 lines
1.8 KiB
R
58 lines
1.8 KiB
R
% Generated by roxygen2 (4.1.1): do not edit by hand
|
|
% Please edit documentation in R/reactives.R
|
|
\name{invalidateLater}
|
|
\alias{invalidateLater}
|
|
\title{Scheduled Invalidation}
|
|
\usage{
|
|
invalidateLater(millis, session = getDefaultReactiveDomain())
|
|
}
|
|
\arguments{
|
|
\item{millis}{Approximate milliseconds to wait before invalidating the
|
|
current reactive context.}
|
|
|
|
\item{session}{A session object. This is needed to cancel any scheduled
|
|
invalidations after a user has ended the session. If \code{NULL}, then
|
|
this invalidation will not be tied to any session, and so it will still
|
|
occur.}
|
|
}
|
|
\description{
|
|
Schedules the current reactive context to be invalidated in the given number
|
|
of milliseconds.
|
|
}
|
|
\details{
|
|
If this is placed within an observer or reactive expression, that object will
|
|
be invalidated (and re-execute) after the interval has passed. The
|
|
re-execution will reset the invalidation flag, so in a typical use case, the
|
|
object will keep re-executing and waiting for the specified interval. It's
|
|
possible to stop this cycle by adding conditional logic that prevents the
|
|
\code{invalidateLater} from being run.
|
|
}
|
|
\examples{
|
|
\dontrun{
|
|
shinyServer(function(input, output, session) {
|
|
|
|
observe({
|
|
# Re-execute this reactive expression after 1000 milliseconds
|
|
invalidateLater(1000, session)
|
|
|
|
# Do something each time this is invalidated.
|
|
# The isolate() makes this observer _not_ get invalidated and re-executed
|
|
# when input$n changes.
|
|
print(paste("The value of input$n is", isolate(input$n)))
|
|
})
|
|
|
|
# Generate a new histogram at timed intervals, but not when
|
|
# input$n changes.
|
|
output$plot <- renderPlot({
|
|
# Re-execute this reactive expression after 2000 milliseconds
|
|
invalidateLater(2000)
|
|
hist(isolate(input$n))
|
|
})
|
|
})
|
|
}
|
|
}
|
|
\seealso{
|
|
\code{\link{reactiveTimer}} is a slightly less safe alternative.
|
|
}
|
|
|