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 R-related questions, the question does not contain code or reproducible example, I hope that it touches on practical and relevant matters.
I'm working on a modular Shiny app that has the following structure:
server.R
- contains some key functions and first few initial graphicsui.R
- provides basic user interface frameworkdata
- folder with some data files that are not sourced dynamically
list.csv
- sample file with data...
- other data filesfunctionsAndModules
- folder with *.R
files pertaining to functions and modules
functionCleanGeo.R
- simple function cleaning some data frames of format: cleanDataFrame <- function(data) { ... return(cleanDta) }
moduleTimeSeries.R
- module providing time series analysis doing the following things:
...R
- other modules and functions saved as *.R
files.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:
When it's sufficient to load libraries only in global.R
and when (if at all) it may be required to load libraries across module files and/or server.R
/ ui.r
?
1.2. For example when using shinyTree
package I load it in server.R
and ui.R
as, it is my understanding that this flows from examples. Modules and functions use dplyr
/ tidyr
combination, would it be sufficient to load those packages in global.R
?
My preferred method for loading packages looks like that:
Vectorize(require)(package = c("ggvis", "SPARQL", "jsonlite", "dplyr", "tidyr", "magrittr"), character.only = TRUE)
, will it work fine with the architecture described above?
Shiny applications have two components, a user interface object and a server function, that are passed as arguments to the shinyApp function that creates a Shiny app object from this UI/server pair.
Shiny is an R package that makes it easy to build interactive web apps straight from R. You can host standalone apps on a webpage or embed them in R Markdown documents or build dashboards. You can also extend your Shiny apps with CSS themes, htmlwidgets, and JavaScript actions.
Here my two cents:
app.R
file, at the server side of the app.R
or alternatively at the modules file. fooUI
and fooServer
module functions or inside. Both works. module*.R
file. global.R
file, do not get to the modules, so they can run. My hypothesis is that it doesn't load on the app.R environment. I understood that the global.R is to load share objects from server
and ui
and to set some configuration. If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With