1. Observers vs. reactives
In this video, we will learn about the key differences between observers and reactives.
2. Reactive flow
Reactive flow is all about connecting the different reactive components together. This flowchart summarizes reactive flow in Shiny. For a simple one input, one output app, the flow is as simple as inputs updating outputs. For more complex apps, the flow involves reactive expressions and other shiny constructs like eventReactive that you will learn later.
3. Observers (1/2)
Observers can access reactive sources and reactive expressions, but they don't return a value. Instead they are used primarily for their side effects, which typically involves sending data to the web browser.
In this app, we use a simple observer that displays a greeting in a modal dialog, in response to a user entering their name.
4. Observers (2/2)
Here is another app, where we use the function observe to define an observer that displays a notification, using the function showNotification, when a user enters their name. Note that displaying a notification is a side-effect, and no value is returned.
5. Observers vs. reactives
Fundamentally, it is important to remember that:
- reactive() is for calculating values, without side effects
- observe() is for performing actions, with side effects
The key differences between observers and reactive expressions are
- Reactive expressions return values, but observers don’t.
- Observers eagerly respond to changes in their dependencies, while reactive expressions are lazy.
- Observers are primarily useful for their side effects, whereas, reactive expressions must NOT have side effects
6. Let's practice!
You are now ready to practice.