Each chapter in the Shiny App-Packages
book has a matching Shiny application, and each application lives on
its own branch of the sap
repository. Cloning branches by hand gets tedious after the second or
third chapter, so shinypak handles it for you. In this
vignette I’ll cover authenticating with GitHub, finding an app,
launching or downloading it, and checking what a folder contains with
is_r_package().
Each function also comes with its call stack: the functions it calls,
and the functions those call. I’ve built these with stackcallr,
which reads the source code without running it. The call stacks show
what happens when you call a function, so you’ll know which package
(gert, shiny, or pkgload) is
doing the work if something goes wrong.
Authentication
shinypak assumes you have GitHub and RStudio (or
Positron) synced. The gert
package website describes how this works:
“In
gert, authentication is done automatically using thecredentialspackage. This package calls out to the local OS credential store which is also used by the git command line. Thereforegertwill automatically pick up on https credentials that are safely stored in your OS keychain.”
list_apps() calls the git command line directly, so
you’ll also need git
installed and on your PATH.
Workflow
After authenticating with GitHub, a typical workflow with
shinypak has five steps.
- Install and load the package:
install.packages('pak')
pak::pak("mjfrigaard/shinypak", force = TRUE)Find an example application in a chapter to follow along with (we’ll use
02.3_proj-app).Confirm the branch name with
list_apps(). Supplying aregexreturns only the branches matching a chapter or topic:
list_apps(regex = "^02.3")
#> branch last_updated
#> 4 02.3_proj-app 2025-03-11 13:43:18
list_apps(regex = "proj-app")
#> branch last_updated
#> 4 02.3_proj-app 2025-03-11 13:43:18-
list_apps()makes a bare clone ofsap(branch names and commit history, no files) withgit_clone_bare(), then reads the branches withgert::git_branch_list(). The call stack below shows both steps:
stackcallr::call_tree_dir("R", root = "list_apps", include_ns = "gert")#> █─list_apps
#> ├─git_clone_bare
#> ├─git_branch_list
#> ├─sep_cols
#> └─%nin%
- To launch an app from the Shiny App-Packages
book, supply the name of the branch to
launch():
launch(app = "<branch>")- For example, the
02.3_proj-appbranch comes from the early chapters of Shiny App-Packages, so the app isn’t quite an app-package yet:
launch(app = "02.3_proj-app")-
launch()checks whether the application has already been downloaded. If it hasn’t, the application files are downloaded into a folder in the current working directory before the app launches:
``` bash
✔ '02.3_proj-app' not in local working directory [59ms]
✔ downloading '02.3_proj-app' [10.7s]
✔ got '02.3_proj-app' [163ms]
✔ Launching app with: shiny::shinyAppDir('02.3_proj-app/app.R')
```
- If the branch stores an app-package,
launch()loads the package and then launches the application:

- The call stack for
launch()shows where each path goes.get_app()downloads the branch, andis_r_package()decides how it runs: app-packages are loaded withload_all()and run withrunApp(), and plain apps run withshinyAppDir():
stackcallr::call_tree_dir("R", root = "launch",
include_ns = c("gert", "shiny", "pkgload"))#> █─launch
#> ├─█─get_app
#> │ └─git_clone
#> ├─█─is_r_package
#> │ ├─█─is_pkg_description
#> │ │ └─check_text_field
#> │ └─█─is_pkg_rproj
#> │ └─check_text_field
#> ├─load_all
#> ├─runApp
#> └─shinyAppDir
- If you’d prefer to download the application without launching it,
call
get_app(). The branch is downloaded into your current working directory:
get_app(app = "05_roxygen2")
- Supply
open = TRUEto open the new project in a fresh IDE session:
get_app(app = "05_roxygen2", open = TRUE)
If the app is already downloaded, the files are updated with the latest commit to the branch.
get_app()has the shortest call stack.git_clone()downloads the branch, andopenProject()opens it whenopen = TRUE:
stackcallr::call_tree_dir("R", root = "get_app",
include_ns = c("gert", "rstudioapi"))#> █─get_app
#> ├─git_clone
#> └─openProject
Helper functions
Not every folder with a DESCRIPTION file is an R
package, and not every .Rproj file is configured for
package development. is_r_package() checks both. Consider
the three folders below:
If the folder contains an R package, is_r_package()
returns TRUE.
is_r_package(path = system.file("pkg", package = "shinypak"))
#> [1] TRUESetting verbose = TRUE prints the details of each
check:
is_r_package(
path = system.file("pkg", package = "shinypak"),
verbose = TRUE)
#> ✔ Package found!
#> ✔ Version found!
#> ✔ License found!
#> ✔ Description found!
#> ✔ Title found!
#> ✔ Authors@R or Author/Maintainer found!
#> ✔ BuildType found!
#> ✔ PackageUseDevtools found!
#> ✔ PackageInstallArgs found!
#> ✔ '/home/runner/work/_temp/Library/shinypak/pkg' is an R package (RS build tools configured)
#> [1] TRUEThe verbose output tells you what’s missing, not just whether the
check failed. Consider the app folder, which has both a
DESCRIPTION and an .Rproj file:
is_r_package(
path = system.file("app", package = "shinypak"),
verbose = TRUE)
#> ✖ Package not in DESCRIPTION!
#> ✖ Version not in DESCRIPTION!
#> ✔ License found!
#> ✖ Description not in DESCRIPTION!
#> ✔ Title found!
#> ✖ Authors@R or Author/Maintainer not in DESCRIPTION!
#> ✖ BuildType not in .Rproj!
#> ✖ PackageUseDevtools not in .Rproj!
#> ✖ PackageInstallArgs not in .Rproj!
#> ✖ '/home/runner/work/_temp/Library/shinypak/app' is not an R package (no RS build tools configured)
#> [1] FALSEThe output above tells us app is missing fields from its
DESCRIPTION, and its .Rproj file isn’t
configured with RStudio’s build tools.
What is_r_package() calls
The call stack for is_r_package() shows the two checks.
is_pkg_description() reads the DESCRIPTION
file, is_pkg_rproj() reads the .Rproj file,
and both search for fields with check_text_field():
stackcallr::call_tree_dir("R", root = "is_r_package")#> █─is_r_package
#> ├─█─is_pkg_description
#> │ └─check_text_field
#> └─█─is_pkg_rproj
#> └─check_text_field
Lookup table
topic_lookup connects each branch to its
part and chapter in the book:
topic_lookup| branch | part | chapter |
|---|---|---|
| 02.1_shiny-app | Intro | Shiny |
| 02.2_movies-app | Intro | Shiny |
| 02.3_proj-app | Intro | Shiny |
| 03.1_description | Intro | Packages |
| 03.2_rproj | Intro | Packages |
| 03.3_create-package | Intro | Packages |
| 04_devtools | Intro | Development |
| 05_roxygen2 | App-packages | Documentation |
| 06.1_exports | App-packages | Dependencies |
| 06.2_imports | App-packages | Dependencies |
| 07_data | App-packages | Data |
| 08_launch | App-packages | Launch |
| 09_inst | App-packages | External files |
| 10_debugger | Debugging | Debugging in Positron/RStudio |
| 11_debug-print | Debugging | Print debugging methods |
| 12.1_debug-mods | Debugging | Debugging modules |
| 12.2_mod-comms | Debugging | Debugging module communication |
| 13_logging | Debugging | Logging app behaviors |
| 14_tests_suite | Tests | Building testthat test suite |
| 15_specs | Tests | Test specifications |
| 16.1_test-help | Tests | Using ensure to help write tests |
| 16.2_test-data | Tests | Storing and using test data |
| 16.3_test-logger | Tests | Writing a test logging helper function |
| 16.4_test-snapshots | Tests | Test snapshots |
| 17_test-modules | Tests | Testing modules |
| 18_test-system | Tests | System tests |
| 19_shinyappsio | Deploy | Deploy to shinyapps.io |
| 20_docker | Deploy | Deploying with Docker |
| 21.1_gha-style | Deploy | Deploying with GitHub Actions (styling code) |
| 21.2_gha-shiny-deploy | Deploy | Deploying shiny app with GitHub Actions |
| 21.3_gha-shiny-docker | Deploy | Deploying shiny app with Docker and GitHub Actions |
| 22_webr | Deploy | Deploying with webR and shinylive |
| 23.1_shinyelectron | Deploy | Desktop apps with shinyelectron |
| 23.2_shinyelectron-dmg | Deploy | Building a macOS installer (.dmg) |
| 23.3_shinyelectron-deb | Deploy | Building a Linux installer (.deb) |
| 24_pkgdown | Deploy | Deploying a package website |
| 25_golem | Frameworks | golem framework |
| 26_leprechaun | Frameworks | leprechaun framework |
| 27_rhino | Frameworks | rhino framework |
| 28_llm-shiny-assist | Shiny & LLMs | LLMs with Shiny Assistant |
| 29_llm-ellmer | Shiny & LLMs | LLMs with ellmer package |
| 30_llm-chores | Shiny & LLMs | LLMs with chores package |
| 31_llm-gander | Shiny & LLMs | LLMs with gander package |
| 32_llm-btw | Shiny & LLMs | LLMs with btw package |
Recap
The workflow is three functions: list_apps() finds the
branch you want, launch() runs it, and
get_app() downloads it without running it.
is_r_package() confirms whether a folder is a package, an
app, or just a project. The call stacks show that gert does
the downloading, shiny and pkgload do the
launching, and is_r_package() decides which launch path an
app takes.
The source for every application is on a branch of the sap
repository, and each branch maps back to a chapter in Shiny
App-Packages.