Shiny scoping rules - where to load libraries in modular architecture
<p>With this question I'm only interested in obtaining some clarity on a best approach to using packages while working with a Shiny app. Despite the fact that, contrary to good practice on asking <a href="https://stackoverflow.com/q/5963269/1655567">R-related questions</a>, the question does not contain code or reproducible example, I hope that it touches on practical and relevant matters.</p>

<h1>Problem</h1>

<p>I'm working on a <a href="http://shiny.rstudio.com/articles/modules.html" rel="nofollow noreferrer">modular</a> Shiny app that has the following structure:</p>

<ul>
<li><code>server.R</code> - contains some key functions and first few initial graphics</li>
<li><code>ui.R</code> - provides basic user interface framework</li>
<li><strong><code>data</code></strong> - folder with some data files that are not sourced dynamically

<ul>
<li><code>list.csv</code> - sample file with data</li>
<li><code>...</code> - other data files</li>
</ul></li>
<li><strong><code>functionsAndModules</code></strong> - folder with <code>*.R</code> files pertaining to functions and modules

<ul>
<li><code>functionCleanGeo.R</code> - simple function cleaning some data frames of format: <code>cleanDataFrame &lt;- function(data) { ... return(cleanDta) }</code></li>
<li><code>moduleTimeSeries.R</code> - module providing time series analysis doing the following things:

<ul>
<li>generating user interface</li>
<li>sourcing data</li>
<li>generating charts</li>
</ul></li>
<li><code>...R</code> - other modules and functions saved as <code>*.R</code> files.</li>
</ul></li>
</ul>

<h2>Libraries</h2>

<p>What I would like to know is how to approach loading packages that would be most optimal for the app structure outlined above. In particular, I would like to know:</p>

<ol>
<li><p>When it's sufficient to load libraries <strong>only</strong> in <code>global.R</code> and when (if at all) it may be required to load libraries across module files and/or <code>server.R</code> / <code>ui.r</code>?</p>

<p>1.2. For example when using <a href="https://github.com/trestletech/shinyTree" rel="nofollow noreferrer"><strong><code>shinyTree</code></strong></a> package I load it in <code>server.R</code> and <code>ui.R</code> as, it is my understanding that this flows from examples. Modules and functions use <code>dplyr</code> / <code>tidyr</code> combination, <em>would it be sufficient to load those packages in <code>global.R</code></em>?</p></li>
<li><p>My preferred method for loading packages looks like that: 
<code>Vectorize(require)(package = c("ggvis", "SPARQL", "jsonlite", "dplyr", "tidyr", "magrittr"), character.only = TRUE)</code>, will it work fine with the architecture described above?</p></li>
</ol>