library(oaPackages)
library(fs)

Getting Started

To create your (first) Shiny application all you need are the R package oaPackages and its createShinySkeleton() function.

Best practices regarding Shiny applications within OA have been updated as of 2022. Therefore, this vignette is associated with version 0.0-12 and onwards.

In its core, createShinySkeleton() creates a file structure within your working directory typical of a regular R package.

It does so by creating files and folders so that:

Depending on the arguments provided to createShinySkeleton(), the author (with e-mail), title of the package, description and first dependencies are directly written to the DESCRIPTION file.

Let’s see it in action. We create a new application under our current working directory (specified under the path argument):

createShinySkeleton(path = "./myShinyApp",
    authorEMail = c("OA" = "info@openanalytics.eu"),
    title = 'One Line Title',
    description = 'A package to show what createShinySkeleton is doing.')
#> [1] TRUE

The following structure is created under myShinyApp.

#> myShinyApp
#> ├── DESCRIPTION
#> ├── LICENSE
#> ├── NEWS.md
#> ├── R
#> │   ├── app_data.R
#> │   ├── app_fit.R
#> │   ├── app_main.R
#> │   └── app_run.R
#> ├── inst
#> │   ├── app
#> │   │   └── app.R
#> │   ├── extdata
#> │   │   └── cars.csv
#> │   └── www
#> │       ├── custom.css
#> │       └── logo.png
#> ├── man
#> └── tests
#>     ├── testthat
#>     │   └── test-app.R
#>     └── testthat.R

From here on, one can start building a Shiny application. Under the R folder, some files are generated to get you started. These use Shiny Modules. The file app_run.R contains the function runShiny() with the following logic:

# Run the application
shinyApp(
    ui = uiFunction(doDebug = doDebug),
    server = serverFunction(),
    options = list(...)
)

As one can see, we need to pass a uiFunction, a serverFunction and possible options to the runShiny() function. These are already generated in the file app_main.R. If needed, additional arguments of the shinyApp function can be defined.

What’s Next?

As with a regular R package, the development process is to iterate between

  • writing code as R functions
  • load the code (e.g. using devtools::load_all())
  • start the application using runShiny() or in debug mode runShiny(doDebug = TRUE)
  • test your application

For more information about this process, visit the OA Shiny Good Practice.

Once we are happy with the state of an application, we document our progress in the NEWS.md file and we build the entire package, e.g. using R CMD BUILD. Then we can share the entire application (which is then a single file) or directly deploy it.