

ObserveEvent() isolates the block of code in its second argument with isolate(). This pattern uses observeEvent() to connect the change in an action button’s value to the code that the action button should trigger. Whenever the value changes, observeEvent() will run its second argument, which should be a block of code surrounded in braces. ObserveEvent() observes a reactive value, which is set in the first argument of observeEvent(). The state changes when a user clicks the button. Like other widgets, action buttons maintain a state (a value). Why the pattern worksĪction buttons do not automatically generate actions in Shiny.

See this example to learn more about sendCustomMessage(). tags$head(tags$script(src = "message-handler.js")) supplies the JavaScript that makes this possible. In the code above, session$setCustomMessage() generates a popup message. Use observeEvent() to trigger a command with an action button.

The patterns below explain this arrangement and illustrate the most popular ways to use an action button or an action link. These functions monitor the value, and when it changes they run a block of code.

The value is designed to be observed by one of observeEvent() or eventReactive(). You can access this value from within your app as input$ where is the ID that you assigned to your action button.Īction buttons are different from other widgets because the value of an action button is almost never meaningful by itself. The value is an integer that changes each time a user clicks the button. Like all widgets, action buttons have a value.
