The reactiveValues() function
reactiveValues()
creates a list of objects that can operate with reactive values but are not reactive values themselves. The main difference is that reactiveValues
(unlike reactive objects) are not re-executed whenever an input value changes.
Due to this, reactive values are an optimal tool whenever certain register of previous inputs is needed. A good example of this could be counting the number of times an input value changes. In this case, a code is needed where the value of the counter depends on the input value change and on the counter's own previous value. As there is no possibility of operating with reactive values outside a reactive context, this should be inside a reactive context. In this case, as the result will not be displayed inside the application, the code will be inserted inside observe()
.
The first idea would be to place a counter inside observe()
. With the first example, the code should look like this in server.R
:
library(shiny) #initialization...