The isolate() function
isolate()
is a function that does exactly what is expected; it isolates a piece of code. In a Shiny reactive context, this means that it prevents the execution of a piece of code unless, of course, certain condition is met. The condition that isolate()
takes in order to re-execute the piece of code is, however, not evaluated in the usual way (that is, in the way that returns TRUE
or FALSE
), it evaluates whether the object changes or not.
The object to evaluate the condition that is mostly used within isolate()
is the action button. The actionButton()
function, apart from drawing a button in the interface, creates an object, which is mainly a counter that whenever the button is hit, it increases its value by 1
. It becomes clear then why isolate is used mainly with actionButton()
; it is ideal to isolate a piece of code from the reactive context it is in until a button is hit.
Lastly, isolate()
is a function that can be called only within a reactive context, that is,...