Exercise

Trigger reactions with observeEvent()

There are times when you want to perform an action in response to an event. For example, you might want to let the app user download a table as a CSV file, when they click on a "Download" button. Or, you might want to display a notification or modal dialog, in response to a click.

The observeEvent() function allows you to achieve this. It accepts two arguments:

  1. The event you want to respond to.
  2. The function that should be called whenever the event occurs.

In this exercise, you will use observeEvent() to display a modal dialog with help text, when the user clicks on a button labelled "Help". The help text has already been assigned to the variable bmi_help_text.

Instructions

100 XP
  • UI:
    • Add an action button named 'show_help', labelled "Help". You might have to scroll down or collapse the console to view the UI.
  • Server:
    • Uncomment the code # showModal ...
    • Wrap showModal(...) in observeEvent() so that the help text is displayed when a user clicks on the help button