Skip to content

This wraps an expression so that it will be executed one time for a tutorial, based on some condition. The first time the condition is true, the expression will be executed; after that, the expression will not be evaluated again.

The execution state is stored so that if the expression is executed, then the user quits the tutorial and then returns to it, the expression will not be executed a second time.

A common use for one_time is to execute an expression when a section is viewed for the first time.


one_time(session, cond, expr, label = deparse(substitute(cond)))



A Shiny session object.


A condition that is used as a filter. The first time the condition evaluates to true, expr will be evaluated; after that, expr will not be evaluated again.


An expression that will be evaluated once, the first time that cond is true.


A unique identifier. This is used as an ID for the condition and expression; if two calls to one_time() uses the same label, there will be an ID collision and only one of them will execute. By default, cond is deparsed and used as the label.


The result of evaluating expr (one_time() is intended to be called within an event handler).


if (FALSE) {
# This goes in a {r context="server-start"} chunk

# The expression with message() will be executed the first time the user
# sees the section with ID "section-exercise-with-hint".
  function(session, event, data) {
      data$sectionId == "section-exercise-with-hint",
        message("Seeing ", data$sectionId, " for the first time.")