Let's imagine an application that loads the iris
dataset and returns the mean and median of numeric variables based upon the species selected. With the elements seen so far, the output generation process would consist of the following:
iris
datasetAs it has been explained before, every reactive element (like outputs) are re-executed whenever an input changes. So, in this case, these five processes would be in constant re-execution.
However, there is an evident issue in this situation: the dataset is always the same one, so the exact same operation is done every time an input changes. The underlying problem is that the load of the iris dataset does not actually depend on the input passed. In other words, it is independent from the application's reactive process.
Shiny provides, basically, two alternatives to write processes outside a reactive context, by coding it either inside server.R
but prior to the function call that initializes the application, as it is explained in the Example 3 – loading data outside reactive context section, or in
global.R
.