Optimal usage of server.R and global.R
Unlike UI.R
, the core of the code in server.R
and global.R
does not normally differ significantly from normal R code. The mean calculations, statistical functions, and so on are obtained exactly in the same way within a Shiny application as in any other script.
However, in the context where code gets re-executed constantly, like in the Shiny applications, and where eventually a multi-concurrence of users can occur, performance becomes a key factor to avoid collapses.
For example, if the whole application is based on one data source, there is no point in loading it more than once. So, in this case, if the data load code is within a reactive expression in server.R
, the data will be loaded unnecessarily again whenever an input value changes, whereas it could have been loaded just once when the application was loaded.
Here are some tips to optimize your code and considerably reduce your execution time:
- Run once whatever is used by more than one process: In...