App-packages

Expand the callout boxes below to review what we’ve covered in the last four chapters:

1  Whole app game walks through the ‘whole game’ of the app-package development workflow. The application in this example comes from the Packages chapter of Mastering Shiny.

The applications in Chapter 1 (Whole app game) can be accessed with the launch() or get() functions from the shinypak R package:

# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)

Chapter 1 applications:

list_apps(regex = '^01')
## # A tibble: 1 × 2
##   branch            last_updated       
##   <chr>             <dttm>             
## 1 01_whole-app-game 2024-07-30 07:59:35

The Shiny chapter covered

  1. Basic Shiny projects (2.1 Shiny apps)

  2. Shiny app folders (2.3 Project folders) and files (2.4 Project files)

  3. Shiny modules (2.5.1 Modules) and standalone app functions (2.5.2 Standalone app function), and

  4. Other ‘pre-package’ advanced practices (2.6 Additional features) you may have adopted in your Shiny app.

The applications in Chapter 2 (Shiny) can be accessed with the launch() or get() functions from the shinypak R package:

# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)

Chapter 2 applications:

list_apps(regex = '^02')
## # A tibble: 3 × 2
##   branch          last_updated       
##   <chr>           <dttm>             
## 1 02.1_shiny-app  2024-07-30 08:05:21
## 2 02.2_movies-app 2024-07-30 08:07:26
## 3 02.3_proj-app   2024-07-30 08:10:18

Packages illustrates what separates R projects from R packages. This chapter covers:

  1. The essential ingredients of an R package (3.1.1 Functional R packages)

  2. How to create a new Shiny app-package (3.3.1 New Shiny app-packages) and

  3. Convert an existing Shiny app (3.3.2 Converting Shiny projects) into an app-package.

The applications in Chapter 3 (Packages) can be accessed with the launch() or get() functions from the shinypak R package:

# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)

Chapter 3 applications:

list_apps(regex = '^03')
## # A tibble: 3 × 2
##   branch              last_updated       
##   <chr>               <dttm>             
## 1 03.1_description    2024-07-30 08:13:54
## 2 03.2_rproj          2024-07-30 08:16:52
## 3 03.3_create-package 2024-07-30 08:49:24

4  Development introduced the devtools package and its core functions:

  1. load_all() (4.3.1 Load)

  2. document() (4.3.2 Document), and

  3. install() (4.3.3 Install)

The applications in Chapter 2 (Development) can be accessed with the launch() or get() functions from the shinypak R package:

# install.packages('pak')
pak::pak('mjfrigaard/shinypak')
library(shinypak)

Chapter 4 applications:

list_apps(regex = '^04')
## # A tibble: 1 × 2
##   branch      last_updated       
##   <chr>       <dttm>             
## 1 04_devtools 2024-07-30 09:04:23

We now have two branches of shinyrPkgs with a functioning app-package:

  1. In the 04_devtools branch (created in 4.3.3 Install), shinyrPkgs was converted to a package by manually adding the required fields to the DESCRIPTION file, then running the key devtools development functions (load_all(), document(), and install())

  2. In the 03.3_create-package branch (created in 3.3.2 Converting Shiny projects), we used the usethis::create_package() function to convert shinyrPkgs into a package.

The only difference between these two branches lies in the DESCRIPTION file

Package: shinyrPkgs
Title: Shiny App-Packages
Version: 0.0.0.9000
Author: John Smith [aut, cre]
Maintainer: John Smith <John.Smith@email.io>
Description: An R package with a collection of Shiny applications.
License: GPL-3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
1
In the 03.3_create-package branch, the Roxygen: list(markdown = TRUE) field was added (which we will cover in the upcoming documentation chapter).

App-packages

The following chapters will continue with app-package development, emphasizing developing a Shiny application within a package structure. A preview of each topic covered in the upcoming chapters is provided below.

Documentation (Chapter 5)

5  Documentation covers documenting the code in your app-package with roxygen2:

  • Required tags: @title, @description, @details, @param, @return, and @examples
  • App-package tags for modules and standalone app functions: @seealso, @family, and @section

Dependencies (Chapter 6)

6  Dependencies dives into the external (i.e. add-on) functions and packages you’ve used to build your app-package. We’ll also cover how to export functions and objects from your app-packages for others to use.

  • Exporting functions from your package namespace
    • @export/export()
  • Importing functions from add-on packages into your package namespace
    • NAMESPACE directives
    • The Imports field in the DESCRIPTION

Data (Chapter 7)

7  Data covers how to include datasets in your app-package namespace, and the various kinds of data in R packages.

  • Documenting data with roxygen2 using @format, \describe, \item

  • Location of data files: data/ vs. data-raw/ vs. inst/extdata/

Launch (Chapter 8)

The 8  Launch chapter covers how to 1) run your application during development, 2) how to run your app using a standalone app function, and 3) how to deploy your application to shinyapps.io.

  • What goes in app.R?
    • shinyApp() vs. shinyAppDir() vs. runApp()
    • rsconnect::deployApp()

External files (Chapter 9)

9  External files covers how to include external resources (i.e. the images, CSS, html, or other files that are typically included in the www/ folder and served when you run your Shiny app). This chapter also covers other uses for the isnt/ folder in app-packages.

  • www/ vs. inst/

  • Using addResourcePath() with system.file()

Please open an issue on GitHub