Author

Peter Baumgartner

Published

2025-07-06 00:31

Preface

This is work in progress

I have finished about 50% of the book content. Currently I am working on chapter .

The missing 4.8 will be worked out in the next few days.

WATCH OUT: This is neither an accurate replication nor an authoritative textbook.

I am writing this book as a text for others to read because that forces me to become explicit and explain all my learning outcomes more carefully. Please keep in mind that this text is not written by an expert but by a learner.

Text passages with content I am already familiar I have skipped. Section of the original text where I needed more in-depth knowledge I have elaborated and added my own comments resulted from my personal research.

Be warned! In spite of replicating most of the content this Quarto book may contain many mistakes. All the misapprehensions and errors are of course my own responsibility.

Content and Goals of this Book

This Quarto book collects my personal notes, trials and exercises of Mastering Shiny by Hadley Wickham ().

I am learning working with {shiny} because I want to develop a dashboard to display country distributions of different indices (like well-being, carbon footprint, happy planet indicator and most of all inequality statistics). There should be the possibility to display the global distribution via colored world maps, but also to choose a set of country and compare them. For instance I want to use the WHR data 2011, 2012, 2014-2024 and revealing the development of the ladder scores in these years for different countries but also the global distribution via world maps.

Text passages

Quotes and personal comments

My text consists mostly of quotes from the Mastering Shiny book. Sometimes I have them changed slightly to adapt it to the flow of my notes. But I have not shown that it is a quote nor did I reference the position of the (semi)quotes in the book. The reason that I did not quote correctly the text passages from “Mastering Shiny” is that most of the text in this Quarto book is not mine! As I am generally follow the book’s outline using the same text for headers, it should be clear where to find the quotes.

But why I have copied the text anyway? My intention is to slow down my reading from the original resource by copying and making minor tweaks to these text passages (like changing the format of code expression to typewriter font, to set package names in bold and surround them with curly brakes etc. (See ).

Cite “Mastering Shiny”; not this book

Do not quote text passages from this book but from the original ‘Mastering Shiny’!

It should be clear which text passages are my own comments. They are always a personal reflection about the book and my experience with it. If I do not mention explicitly my learning experience and/or my difficulties with the original text/code then there is a good change that the text is from ‘Mastering Shiny’.

To prevent misunderstandings I will illustrate the different text sources with the section in chapter 7 “graphics”.

It should be clear that the box following text under is mine:

“The above code does not work. Hopefully I will learn the solution form the answer to my Posit post.

It is evident that the following explanation and workaround of this problem in is my own comment. It is also obvious that the mentioned solution and the development of the quarto extension is not mine. I have referred to the author Garrick Aden-Buie explicitly. All the other text before and after these two text passages are not mine, but originate from Hadley Wickham‘s “Mastering Shiny”.

Glossary

I am using the {glossary} package () to create links to glossary entries.

R Code 1 : Load glossary

Listing / Output 1: Install and load the glossary package with the appropriate glossary.yml file
Code
## 1. Install the glossary package:
## https://debruine.github.io/glossary/

library(glossary)

## If you want to use my glossary.yml file:

## 1. fork my repo
##    https://github.com/petzi53/glossary-pb

## 2. Download the `glossary.yml` file from
##    https://github.com/petzi53/glossary-pb/blob/master/glossary.yml)

## 3. Store the file on your hard disk
##    and change the following path accordingly

glossary::glossary_path("../glossary-pb/glossary.yml")

If you hover with your mouse over the double underlined links it opens an window with the appropriate glossary text. Try this example: WHR.

WATCH OUT! Glossary is my private learning vehicle

I have added many of the glossary entries when I was working through other books either taking the text passage of these books I was reading or via an internet recherche from other resources. Sometimes I have added the source of the glossary entry as an abbreviation or as an URL. Many definitions were provided by the KI provided within the search of my Brave browser.

If you fork my repository of these notes then the glossary will not work out of the box. Load down the glossary.yml file from my glossary-pb GitHub repo, store it on your hard disk and change the path in the code chunk accordingly.

In any case I am the only responsible person for the glossary text, especially if I have used text from other resources wrongly. Again: The main purpose of the glossary is to support my personal learning venture.

R Code and Datasets

During coding I am following the Tidyverse Style Guide and the conventions explained in Rmarkdown, () a book written with {bookdown} (), a predecessor of Quarto.

  • There are no prompts (> and +) to R source code.
  • The text output is commented out with two hashes ## by default. This is for your convenience when you want to copy and run the code. The text output will be ignored since it is commented out.
  • Inline code and filenames are formatted in a typewriter font (e.g., knitr::knit('foo.Rmd')).
  • Package names are also formatted in a typewriter font but bold an in curly parenthesis (e.g., {rmarkdown}).
  • Function names are followed by parentheses (e.g., bookdown::render_book()). The double-colon operator :: means accessing an object from a package.

Additionally I am adopting the following convention: Whenever I use Shiny with capital letter I am referring to the app. In contrast to {shiny} which is pointing to the R package.

For learning purposes I am practicing {shiny} in two modes:

  1. {shiny} app: I am writing the code in extra app.R files as explained in the book. I create folders with the number of the chapters, eg., apps-01, apps-02. Inside of these chapter folders I put the folders for the {shiny} examples with self explanatory names so that one can get and distinguish the example files that all have the name app.R. Additionally I order these examples with numbers that represents their appearance in the text, e.g., 01-hello-world, 02-greetings1 03-greetings2, etc.
  2. {shinylife-r}: Additionally I provide the example as standalone {shinylive} Quarto examples. They have two different version: One is the source code shown as code listing but not evaluated. The other is the working {shinylive} example. This seems to me a nice way to communicate my learning experiences and the results of the {shiny} code. All these code chunks start with {shinylive-r} instead {r} in the header.
Caution

I am not using always the exact code snippets of the book, because I am not only replicating the code to see how it works but also to change the values of parameters to observe their influences.

Annex

In some of my book notes I provide files in the annex. They contain experiments not directly in line with the book but inspired by my reading of the book.

Often you will also find an annex file with a standardized short description of all my used packages, sometimes added with notes about my personal experiences with this package. An example of the standardized format gives you the following .

Glossary package

Package Profile: glossary

{glossary}: Glossaries for Markdown and Quarto Documents ()

Add glossaries to markdown and quarto documents by tagging individual words. Definitions can be provided inline or in a separate file.

There is a lot of necessary jargon to learn reading new books. The goal of {glossary} is to provide a lightweight solution for making glossaries in educational materials written in quarto or R Markdown. This package provides functions to link terms in text to their definitions in an external glossary file, as well as create a glossary table of all linked terms at the end of a section.


In the meantime {glossary} is for me a very important learning vehicle. Whenever an expression appears with a doubled underlined link I know that I will get more information by hovering the mouse over the underlined text.

There is a little inconvenience with abbreviation that could also be part of another glossary entry text string (e.g., API and Capital Income). My workaround is to end the short abbreviation with an additional ‘x’ and then to call the glossary with the x-version follwed by the text that should be appear in the document (e.g., r glossary(“APIx”, “API”)). This double format is a standard feature of the {glossary} package so that you can adapt the appearing text to the glossary entry (e.g., singular/plural or other grammar changes).

Resources

Resource 1 : Resources used for this Quarto book

Private Functions

XXX: [DESCRIBE PRIVATE FUNCTION USED IN THIS BOOK]

Glossary Entries

term definition
APIx An API, or application programming interface, is a set of defined rules that enable different applications to communicate with each other. It acts as an intermediary layer that processes data transfers between systems, letting companies open their application data and functionality to external third-party developers, business partners, and internal departments within their companies. (<a href="https://www.ibm.com/topics/api">IBM</a>)
Capital Income Capital income is defined as the sum of property income, including dividends, interest gains, reinvested earnings on foreign direct investment, investment income disbursements and land rents ([Distributional National Accounts (DINA) for Austria, 2004-2016](https://wid.world/document/distributional-national-accounts-dina-for-austria-2004-2016-world-inequality-lab-wp-2020-23/)).
WHR The World Happiness Reports are a partnership of Gallup, the Oxford Wellbeing Research Centre, the UN Sustainable Development Solutions Network, and the WHR’s Editorial Board. The report is produced under the editorial control of the WHR Editorial Board. The Reports reflects a worldwide demand for more attention to happiness and well-being as criteria for government policy. It reviews the state of happiness in the world today and shows how the science of happiness explains personal and national variations in happiness. (https://worldhappiness.report/about/)

Session Info

Session Info

Code
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.5.1 (2025-06-13)
#>  os       macOS Sequoia 15.5
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/Vienna
#>  date     2025-07-04
#>  pandoc   3.7.0.2 @ /opt/homebrew/bin/ (via rmarkdown)
#>  quarto   1.8.4 @ /usr/local/bin/quarto
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package      * version    date (UTC) lib source
#>  cli            3.6.5      2025-04-23 [1] CRAN (R 4.5.0)
#>  commonmark     1.9.5      2025-03-17 [1] CRAN (R 4.5.0)
#>  curl           6.4.0      2025-06-22 [1] CRAN (R 4.5.0)
#>  dichromat      2.0-0.1    2022-05-02 [1] CRAN (R 4.5.0)
#>  digest         0.6.37     2024-08-19 [1] CRAN (R 4.5.0)
#>  evaluate       1.0.4      2025-06-18 [1] CRAN (R 4.5.0)
#>  farver         2.1.2      2024-05-13 [1] CRAN (R 4.5.0)
#>  fastmap        1.2.0      2024-05-15 [1] CRAN (R 4.5.0)
#>  glossary     * 1.0.0.9003 2025-06-08 [1] local
#>  glue           1.8.0      2024-09-30 [1] CRAN (R 4.5.0)
#>  htmltools      0.5.8.1    2024-04-04 [1] CRAN (R 4.5.0)
#>  htmlwidgets    1.6.4      2023-12-06 [1] CRAN (R 4.5.0)
#>  jsonlite       2.0.0      2025-03-27 [1] CRAN (R 4.5.0)
#>  kableExtra     1.4.0      2024-01-24 [1] CRAN (R 4.5.0)
#>  knitr          1.50       2025-03-16 [1] CRAN (R 4.5.0)
#>  lifecycle      1.0.4      2023-11-07 [1] CRAN (R 4.5.0)
#>  litedown       0.7        2025-04-08 [1] CRAN (R 4.5.0)
#>  magrittr       2.0.3      2022-03-30 [1] CRAN (R 4.5.0)
#>  markdown       2.0        2025-03-23 [1] CRAN (R 4.5.0)
#>  R6             2.6.1      2025-02-15 [1] CRAN (R 4.5.0)
#>  RColorBrewer   1.1-3      2022-04-03 [1] CRAN (R 4.5.0)
#>  rlang          1.1.6      2025-04-11 [1] CRAN (R 4.5.0)
#>  rmarkdown      2.29       2024-11-04 [1] CRAN (R 4.5.0)
#>  rstudioapi     0.17.1     2024-10-22 [1] CRAN (R 4.5.0)
#>  rversions      2.1.2      2022-08-31 [1] CRAN (R 4.5.0)
#>  scales         1.4.0      2025-04-24 [1] CRAN (R 4.5.0)
#>  sessioninfo    1.2.3      2025-02-05 [1] CRAN (R 4.5.0)
#>  stringi        1.8.7      2025-03-27 [1] CRAN (R 4.5.0)
#>  stringr        1.5.1      2023-11-14 [1] CRAN (R 4.5.0)
#>  svglite        2.2.1      2025-05-12 [1] CRAN (R 4.5.0)
#>  systemfonts    1.2.3      2025-04-30 [1] CRAN (R 4.5.0)
#>  textshaping    1.0.1      2025-05-01 [1] CRAN (R 4.5.0)
#>  vctrs          0.6.5      2023-12-01 [1] CRAN (R 4.5.0)
#>  viridisLite    0.4.2      2023-05-02 [1] CRAN (R 4.5.0)
#>  xfun           0.52       2025-04-02 [1] CRAN (R 4.5.0)
#>  xml2           1.3.8      2025-03-14 [1] CRAN (R 4.5.0)
#>  yaml           2.3.10     2024-07-26 [1] CRAN (R 4.5.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.5-arm64/library
#>  [2] /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library
#>  * ── Packages attached to the search path.
#> 
#> ──────────────────────────────────────────────────────────────────────────────

References

DeBruine, Lisa. 2023. “Glossary: Glossaries for Markdown and Quarto Documents.” https://doi.org/10.32614/CRAN.package.glossary.
Wickham, Hadley. 2021. Mastering Shiny: Build Interactive Apps, Reports, and Dashboards Powered by R. O’Reilly UK Ltd.
Xie, Yihui. 2017. Bookdown: Authoring Books and Technical Documents with R Markdown. Boca Raton, FL: Chapman & Hall/CRC: the R Series. https://bookdown.org/yihui/bookdown/.
Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. 1st ed. Chapman; Hall/CRC.

  1. The parenthesis are my own addition not applied in the mentioned RMarkdown book.↩︎