Welcome

This book is under active development and intended for a 2021 Q4 release in the R Series by Chapman & Hall.

Is this book for me?

You are an experienced Shiny user and you want to learn more about the underlying web technologies so that you can quickly customize your apps. Good new: basic knowledge in HTML, CSS and JavaScript is a plus but not mandatory.

If you fulfill the above prerequisites, you should read this book if you already happened to ask one of the following questions:

  • Do you want to know how to develop shiny apps with a more professional look and feel?
  • Have you ever wondered how to design new input widgets to unleash interactivity?
  • Do you want to better handle JS and CSS in your apps?
  • How may I develop a mobile friendly template for Shiny?
  • How may I include React in my shiny apps?
  • Are you simply curious about what happens under the hood?

Learning objectives

This book will help you to:

  • Understand how Shiny deals with the classic web development standards and what are the main differences.
  • Manipulate HTML tags from R to create custom layouts.
  • Harness the power of CSS and JavaScript to quickly design apps standing out from the pack.
  • Discover the steps to import and convert existing web frameworks like Bootstrap 4, framework7.
  • Learn how Shiny internally deals with inputs.
  • Learn more about less documented Shiny mechanisms (websockets, sessions, …).

Book structure

This book is organized into seven parts:

  • Part 1 demonstrates the link between Shiny and the classic web technologies like HTML, CSS and JavaScript. Some of the necessary web development knowledge are gradually introduced, to be able to read the book. We explore the web dependencies behind Shiny such as Bootstrap and jQuery. We dive into the htmltools (Cheng, Sievert, et al. 2021) package, providing functions to create and manipulate HTML tags from R as well as manage web dependencies.

  • Part 2 focuses on cascading stylesheet (CSS) and Sass (Syntactically Awesome Style Sheets). We provide the reader with basic CSS knowledge to get the most out of Sass, a powerful tool to seamlessly alter Shiny apps style, in a more reproducible manner. All along this part, we showcase examples from the R community like fresh (Perrier and Meyer 2020b) and bslib (Sievert and Cheng 2021), to significantly beautify apps with only few lines of code.

  • Part 3 contains chapters dedicated to the Shiny input system. This part starts with a JavaScript hands on, then exposes how Shiny works under the hood by introducing the websockets which allows the communication between R and JavaScript. We explore the Shiny input life cycle, that is how they are created and updated. We expose JS techniques to get rid of unnecessary renderUI patterns that may speed up Shiny apps. This part contains many hidden gems to significantly and quickly enhance apps.

  • Part 4 focuses on the development of a new template for Shiny by demonstrating examples from the tablerDash (Granjon 2020) package. These, and more may be explored further as part of the RinteRface project. This case study mobilizes all knowledge acquired in the previous parts.

  • Part 5 introduces a new opinionated package, charpente (Granjon and Coene 2021), that substantially reduce the burden of JavaScript management during the development of Shiny extensions.

  • Part 6 dives into mobile web development through a practical study involving a rework of shinyMobile (Granjon, Perrier, and Rudolf 2021). We give a brief introduction to the progressive web application world with some patterns to get started like service workers, web manifests, offline pages.

  • Part 7 exposes other alternatives like React, taking examples from the reactR (Inc et al. 2021) package.

Parts are sorted by difficulty level, the last one being the most technical. However, this does not mean the reader must read all chapters. Given the very heterogeneous background of the community, some people may focus on the JavaScript section, while others will read the Sass part or the mobile development examples. Some patterns exposed in this book may apply to classic Shiny apps projects, that are not necessarily meant to extend Shiny per se, but may need a highly customized experience. Beyond the aesthetic aspect, this book tries to expose best practices to develop optimized shiny apps!

By the end of that book, the reader should be able to entirely customize Shiny in a reasonable amount of time.

Code structure

This book has a side package containing all the necessary material to run the code without having to reload each previous snippet.

remotes::install_github(
"DivadNojnarg/outstanding-shiny-ui-code"
)
library(OSUICode)

About RinteRface

The RinteRface project is an initiative aiming to provide one of the most famous HTML templates to Shiny. Everything started by the collaboration of John Coene and David Granjon early 2018 on shinybulma (Coene and Granjon 2021) to officially release RinteRface November 2018 with shinydashboardPlus (Granjon 2021d), bs4Dash (Granjon 2021a) as line-up packages.

The biggest RinteRface accomplishment is probably the work in progress shinyMobile package, which was initially called {shinyF7}, in collaboration with the dreamRs team.

Since 2019, RinteRface has been involved in various R related events like local R meetups or conferences (Zurich R User Group, baselR, useR2019, satRdayNeuchatel2020, e-Rum2020, RPharma2020).

RinteRface is a contributor in the Shiny Developers Series, hosted by Eric Nantz, also known as the theRcast.

RinteRface work has been awarded several times at the 2 latest shiny contests (2019 and 2020), through contributions like:

  • A virtual lab for teaching physiology (2019), the Apps.Physiol plateform, fuelled by bs4Dash and hosted in {CaPO4Sim} (Granjon 2021b)
The virtual patient simulator of {CaPO4Sim}

FIGURE 0.1: The virtual patient simulator of {CaPO4Sim}

{deminR}, a minesweeper for R

FIGURE 0.2: {deminR}, a minesweeper for R

RinteRface is very grateful to the R community and this book is a sort of acknowledgment!

Acknowledgements

  • I’d like to warmly thanks all CRC reviewers: Emily Riederer, Barret Schloerke and … for their valuable comments and help.
  • Howard Baek for accepting to test almost all chapters. Howard was the perfect book target with good knowledge in Shiny and beginner level in web development.
  • Many thanks to Hadley Wickham for his general thoughts about the book organization. This was really helpful to reorder the content.
  • I am very grateful to Douglas Robinson for proof reading the first book manuscript and fixing many typos it contained.
  • A special thanks to my friends John and Victor for contributing to RinteRface.
  • Thanks to the ThinkR team for providing material support during most of the RinteRface workshops.
  • RinteRface and this book won’t exist without the amazing R community. Thanks for their valuable feedback.

Packages

This book was built with R version 3.6.1 (2019-07-05) and the following packages:

package version source
apexcharter 0.1.8 CRAN (R 3.6.2)
blaze 0.0.1 Github (nteetor/blaze@0adb2ec)
blogdown 1.1 CRAN (R 3.6.2)
brochure 0.0.0.9020 Github (ColinFay/brochure@33a1c2f)
bs4Dash 2.0.1.9000 local
bslib 0.2.4 CRAN (R 3.6.1)
CaPO4Sim 0.2.0.9000 local
charpente 0.0.0.9000 local
deminR 0.0.0.9000 Github (DivadNojnarg/deminR@e0bf665)
dplyr 1.0.3 CRAN (R 3.6.2)
fresh 0.2.0 CRAN (R 3.6.2)
ggplot2 3.3.3 CRAN (R 3.6.2)
golem 0.3.1 CRAN (R 3.6.2)
htmltools 0.5.1.9005 Github (rstudio/htmltools@7e64cd9)
httpuv 1.5.5 CRAN (R 3.6.2)
httr 1.4.2 CRAN (R 3.6.2)
jsonlite 1.7.2 CRAN (R 3.6.2)
jstools 0.1.0 Github (dreamRs/jstools@5689973)
magrittr 2.0.1 CRAN (R 3.6.2)
OSUICode 0.0.0.9000 local
purrr 0.3.4 CRAN (R 3.6.2)
reactR 0.4.4 CRAN (R 3.6.1)
sass 0.3.1 CRAN (R 3.6.1)
scales 1.1.1 CRAN (R 3.6.2)
shiny 1.6.0 CRAN (R 3.6.2)
shiny.router 0.2.2 CRAN (R 3.6.2)
shinybulma 0.0.2.9000 Github (RinteRface/shinybulma@93855e2)
shinydashboard 0.7.1 CRAN (R 3.6.0)
shinydashboardPlus 2.0.2 local
shinyjs 2.0.0 CRAN (R 3.6.1)
shinylogs 0.1.7 CRAN (R 3.6.0)
shinyMobile 1.0.0.9001 Github (RinteRface/shinyMobile@3470895)
shinyWidgets 0.5.7 CRAN (R 3.6.2)
tablerDash 0.1.5 Github (RinteRface/tablerDash@341efde)
testthat 3.0.2 CRAN (R 3.6.2)
thematic 0.1.2 CRAN (R 3.6.2)
waiter 0.2.1.9000 Github (JohnCoene/waiter@d3f7aaf)
websocket 1.3.1 CRAN (R 3.6.2)