Preface
Shiny App-Packages attempts to combine and distill Shiny and R package development practices from multiple resources.
Why this book?
Did you read R Packages, 2ed and find it difficult to apply package development practices to your Shiny application?
R Packages, 2ed is the premier resource for learning the best practices when creating functions, writing documentation, managing package namespaces, and many other fundamental aspects of package development. However, R Packages, 2ed primarily focuses on creating conventional R packages, so it doesn’t cover Shiny programming (designing user interfaces, server-side computations, modules, etc.). Moreover, testing and debugging a Shiny application differs from the traditional methods used in R packages.
Did you read Mastering Shiny and want to learn more about package development?
Mastering Shiny is an excellent introduction to the world of Shiny and provides a foundation of best practices for developing applications. R packages are introduced near the end of Mastering Shiny, and this chapter is a great place to start.1 However, to fully understand and appreciate the benefits of developing your Shiny app as an R package, it’s helpful to have an example app-package that includes the full suite of the package development tools (loading, documenting, testing, installing, etc.).2
Other Shiny Resources
Throughout the course of writing this book, the Shiny community has grown and other resources have been published for developing and customizing Shiny applications. Two popular resources are Engineering Production-Grade Shiny Apps and Outstanding User Interfaces with Shiny.
Engineering Production-Grade Shiny Apps introduces the golem package, which is an ‘opinionated framework for building production-grade Shiny applications’. golem offers a robust and standardized way to build, maintain, and deploy production-grade Shiny apps. Whether due to the learning curve, number of features, dependencies, or a particular set of deployment constraints, golem might not be the right fit for your application.3
Outstanding User Interfaces with Shiny ‘addresses a specific gap between the beginner and advanced level’ focusing on customizing your Shiny application with HTML, CSS and JavaScript. It introduces charpente, which streamlines the creation of Shiny development by quickly creating an R package, importing external web dependencies for JavaScript and CSS, initializing input/output bindings, and providing custom handler boilerplates. charpente also offers a high-level interface to htmltools (the workhorse that converts R code to web-friendly HTML).
We’ll cover both of these texts more in the frameworks section.
Development Environments
The two integrated development environments (IDEs) I will be demonstrating are RStudio and Positron.
RStudio is a popular integrated development environment (IDE) that streamlines many R package development tasks. I’d previously connected this IDE to the definitions above for R package and Shiny app-packages. Specifically, the package development tools provided in the Build pane and the devtools package.
Positron is Posit’s new integrated development environment (IDE) designed to improve productivity and performance across multiple programming languages. Building on RStudio’s success, Positron offers a sleek, user-friendly interface while keeping powerful tools for debugging, profiling, and interactive visualizations.
Most of the book will focus on developing Shiny app-packages in RStudio, because Positron is under active development. When I’m including information specific to particular IDE, I will use icons to differentiate Positron from RStudio (
vs.
).
Other tools
Developing R packages in RStudio or Positron is not required. There are alternative IDEs and tools, and many developers employ these setups (VS Code, PyCharm, Jupyter Lab, Colab, etc). Package development outside RStudio would look almost identical to development in the IDE:
Create the package structure (
R/folder for.Rscripts,man/folder for documentation,data/folder for datasets, etc.)Create
DESCRIPTIONandNAMESPACEfiles, etc.Ensure the package can be installed and loaded into an R session.
The development workflow functions we’ll cover work just about anywhere you can execute R code (i.e., roxygen2::roxygenize(), devtools::load_all(), devtools::install(), etc.).
Acknowledgments
This book is the result of multiple discussions with 1) Shiny developers who were new to writing R packages, 2) R package authors who were learning Shiny development and testing, and 3) new R users who wanted to build a robust and scalable application. Shiny App-Packages wouldn’t have been possible without the contributors below (and I am deeply grateful for all of their help!).
- Henry Bernreuter & Elizabeth Marshallsay for the initial discussions that created the outline for this book
- Andrew Bates for being an exemplary developer and professional, quietly building outstanding UIs, applications, and packages
- Eric Simms for asking so many great questions, reviewing chapters, and giving phenomenal feedback
- Eric Nantz4 for his R podcast, Shiny developer series, workshops, and everything else he does for the Shiny community
- Philip Bowsher for everything he does for the R/Pharma conference and community
- Ted Laderas for his excellent gRadual intRoduction to Shiny course and insightful blog posts
- Jennifer Bryan and Hadley Wickham for their posit::conf(23) package development masterclass workshop.
- Maya Gans for having multiple conversations and Shiny modules and package dependencies
- Leon Samson for his feedback on the testing chapters
Testing Shiny apps requires additional packages and tools to ensure an application’s reliability and performance.↩︎
The ‘Converting an existing app’ chapter provides an example of converting a Shiny app into an R Package. However, many of the helpful package development tools aren’t available (i.e.,
roxygen2tags,NAMESPACEimports/exports, tests, vignettes, etc.).↩︎golemapps are built as packages. Still, EPGSA assumes the reader is ‘comfortable with building an R package.’ (if you’re familiar with package development, EPGSA is an excellent resource).↩︎





