Book Image

Learning Shiny

By : Hernan Resnizky
Book Image

Learning Shiny

By: Hernan Resnizky

Overview of this book

Table of Contents (19 chapters)
Learning Shiny
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Introducing R, RStudio, and Shiny
Index

The observe() function


From the functions covered in this chapter, observe() is definitely the most difficult to understand. Going deeper into the preceding definition, observe() generates outputs from reactive values (inputs) that are not rendered in an application and cannot be used inside another reactive context (for example, renderPlot() or reactive()). As a consequence of this, this function will be rather used to generate a backend process that depends on reactive values.

observe() can be used, for example, to download data depending on reactive values on the server side, such as keeping track of the application's use in a text file, similar to a log. Another very common use of observe() is to update the arguments of an input widget based on reactive values. This will be covered in the last section of this chapter.

In the following example, the application keeps track of the numbers passed as input by saving them in a log. Inside observe(), the passed values (given that it is not NA...