Mastering Shiny

Book description

Master the Shiny web framework—and take your R skills to a whole new level. By letting you move beyond static reports, Shiny helps you create fully interactive web apps for data analyses. Users will be able to jump between datasets, explore different subsets or facets of the data, run models with parameter values of their choosing, customize visualizations, and much more.

Hadley Wickham from RStudio shows data scientists, data analysts, statisticians, and scientific researchers with no knowledge of HTML, CSS, or JavaScript how to create rich web apps from R. This in-depth guide provides a learning path that you can follow with confidence, as you go from a Shiny beginner to an expert developer who can write large, complex apps that are maintainable and performant.

  • Get started: Discover how the major pieces of a Shiny app fit together
  • Put Shiny in action: Explore Shiny functionality with a focus on code samples, example apps, and useful techniques
  • Master reactivity: Go deep into the theory and practice of reactive programming and examine reactive graph components
  • Apply best practices: Examine useful techniques for making your Shiny apps work well in production

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. What Is Shiny?
    2. Who Should Read This Book?
    3. What Will You Learn?
    4. What Won’t You Learn?
    5. Prerequisites
    6. Conventions Used in This Book
    7. Using Code Examples
    8. O’Reilly Online Learning
    9. How to Contact Us
    10. Acknowledgments
    11. How This Book Was Built
  2. I. Getting Started
  3. 1. Your First Shiny App
    1. Introduction
    2. Create App Directory and File
    3. Running and Stopping
    4. Adding UI Controls
    5. Adding Behavior
    6. Reducing Duplication with Reactive Expressions
    7. Summary
    8. Exercises
  4. 2. Basic UI
    1. Introduction
    2. Inputs
      1. Common Structure
      2. Free Text
      3. Numeric Inputs
      4. Dates
      5. Limited Choices
      6. File Uploads
      7. Action Buttons
      8. Exercises
    3. Outputs
      1. Text
      2. Tables
      3. Plots
      4. Downloads
      5. Exercises
    4. Summary
  5. 3. Basic Reactivity
    1. Introduction
    2. The Server Function
      1. Input
      2. Output
    3. Reactive Programming
      1. Imperative Versus Declarative Programming
      2. Laziness
      3. The Reactive Graph
      4. Reactive Expressions
      5. Execution Order
      6. Exercises
    4. Reactive Expressions
      1. The Motivation
      2. The App
      3. The Reactive Graph
      4. Simplifying the Graph
      5. Why Do We Need Reactive Expressions?
    5. Controlling Timing of Evaluation
      1. Timed Invalidation
      2. On Click
    6. Observers
    7. Summary
  6. 4. Case Study: ER Injuries
    1. Introduction
    2. The Data
    3. Exploration
    4. Prototype
    5. Polish Tables
    6. Rate Versus Count
    7. Narrative
    8. Exercises
    9. Summary
  7. II. Shiny in Action
  8. 5. Workflow
    1. Development Workflow
      1. Creating the App
      2. Seeing Your Changes
      3. Controlling the View
    2. Debugging
      1. Reading Tracebacks
      2. Tracebacks in Shiny
      3. The Interactive Debugger
      4. Case Study
      5. Debugging Reactivity
    3. Getting Help
      1. Reprex Basics
      2. Making a Reprex
      3. Making a Minimal Reprex
      4. Case Study
    4. Summary
  9. 6. Layout, Themes, HTML
    1. Introduction
    2. Single-Page Layouts
      1. Page Functions
      2. Page with Sidebar
      3. Multirow
      4. Exercises
    3. Multipage Layouts
      1. Tabsets
      2. Navlists and Navbars
    4. Bootstrap
    5. Themes
      1. Getting Started
      2. Shiny Themes
      3. Plot Themes
      4. Exercises
    6. Under the Hood
    7. Summary
  10. 7. Graphics
    1. Interactivity
      1. Basics
      2. Clicking
      3. Other Point Events
      4. Brushing
      5. Modifying the Plot
      6. Interactivity Limitations
    2. Dynamic Height and Width
    3. Images
    4. Summary
  11. 8. User Feedback
    1. Validation
      1. Validating Input
      2. Canceling Execution with req()
      3. req() and Validation
      4. Validate Output
    2. Notifications
      1. Transient Notification
      2. Removing on Completion
      3. Progressive Updates
    3. Progress Bars
      1. Shiny
      2. Waiter
      3. Spinners
    4. Confirming and Undoing
      1. Explicit Confirmation
      2. Undoing an Action
      3. Trash
    5. Summary
  12. 9. Uploads and Downloads
    1. Upload
      1. UI
      2. Server
      3. Uploading Data
    2. Download
      1. Basics
      2. Downloading Data
      3. Downloading Reports
    3. Case Study
    4. Exercises
    5. Summary
  13. 10. Dynamic UI
    1. Updating Inputs
      1. Simple Uses
      2. Hierarchical Select Boxes
      3. Freezing Reactive Inputs
      4. Circular References
      5. Interrelated Inputs
      6. Exercises
    2. Dynamic Visibility
      1. Conditional UI
      2. Wizard Interface
      3. Exercises
    3. Creating UI with Code
      1. Getting Started
      2. Multiple Controls
      3. Dynamic Filtering
      4. Dialog Boxes
      5. Exercises
    4. Summary
  14. 11. Bookmarking
    1. Basic Idea
      1. Updating the URL
      2. Storing Richer State
    2. Bookmarking Challenges
    3. Exercises
    4. Summary
  15. 12. Tidy Evaluation
    1. Motivation
    2. Data-Masking
      1. Getting Started
      2. Example: ggplot2
      3. Example: dplyr
      4. User-Supplied Data
      5. Why Not Use Base R?
    3. Tidy-Selection
      1. Indirection
      2. Tidy-Selection and Data-Masking
    4. parse() and eval()
    5. Summary
  16. III. Mastering Reactivity
  17. 13. Why Reactivity?
    1. Introduction
    2. Why Do We Need Reactive Programming?
      1. Why Can’t You Use Variables?
      2. What About Functions?
      3. Event-Driven Programming
      4. Reactive Programming
    3. A Brief History of Reactive Programming
    4. Summary
  18. 14. The Reactive Graph
    1. Introduction
    2. A Step-by-Step Tour of Reactive Execution
    3. A Session Begins
      1. Execution Begins
      2. Reading a Reactive Expression
      3. Reading an Input
      4. Reactive Expression Completes
      5. Output Completes
      6. The Next Output Executes
      7. Execution Completes, Outputs Flushed
    4. An Input Changes
      1. Invalidating the Inputs
      2. Notifying Dependencies
      3. Removing Relationships
      4. Re-execution
      5. Exercises
    5. Dynamism
    6. The Reactlog Package
    7. Summary
  19. 15. Reactive Building Blocks
    1. Reactive Values
      1. Exercises
    2. Reactive Expressions
      1. Errors
      2. on.exit()
      3. Exercises
    3. Observers and Outputs
    4. Isolating Code
      1. isolate()
      2. observeEvent() and eventReactive()
      3. Exercises
    5. Timed Invalidation
      1. Polling
      2. Long-Running Reactives
      3. Timer Accuracy
      4. Exercises
    6. Summary
  20. 16. Escaping the Graph
    1. Introduction
    2. What Doesn’t the Reactive Graph Capture?
    3. Case Studies
      1. One Output Modified by Multiple Inputs
      2. Accumulating Inputs
      3. Pausing Animations
      4. Exercises
    4. Antipatterns
    5. Summary
  21. IV. Best Practices
  22. 17. General Guidelines
    1. Introduction
    2. Code Organization
    3. Testing
    4. Dependency Management
    5. Source Code Management
    6. Continuous Integration/Deployment
    7. Code Reviews
    8. Summary
  23. 18. Functions
    1. File Organization
    2. UI Functions
      1. Other Applications
      2. Functional Programming
      3. UI as Data
    3. Server Functions
      1. Reading Uploaded Data
      2. Internal Functions
    4. Summary
  24. 19. Shiny Modules
    1. Motivation
    2. Module Basics
      1. Module UI
      2. Module Server
      3. Updated App
      4. Namespacing
      5. Naming Conventions
      6. Exercises
    3. Inputs and Outputs
      1. Getting Started: UI Input and Server Output
      2. Case Study: Selecting a Numeric Variable
      3. Server Inputs
      4. Modules Inside of Modules
      5. Case Study: Histogram
      6. Multiple Outputs
      7. Exercises
    4. Case Studies
      1. Limited Selection and Other
      2. Wizard
      3. Dynamic UI
    5. Single Object Modules
    6. Summary
  25. 20. Packages
    1. Converting an Existing App
      1. Single File
      2. Module Files
      3. A Package
    2. Benefits
      1. Workflow
      2. Sharing
    3. Extra Steps
      1. Deploying Your App-Package
      2. R CMD check
    4. Summary
  26. 21. Testing
    1. Testing Functions
      1. Basic Structure
      2. Basic Workflow
      3. Key Expectations
      4. User Interface Functions
    2. Workflow
      1. Code Coverage
      2. Keyboard Shortcuts
      3. Workflow Summary
    3. Testing Reactivity
      1. Modules
      2. Limitations
    4. Testing JavaScript
      1. Basic Operation
      2. Case Study
    5. Testing Visuals
    6. Philosophy
      1. When Should You Write Tests?
    7. Summary
  27. 22. Security
    1. Data
    2. Compute Resources
  28. 23. Performance
    1. Dining at Restaurant Shiny
    2. Benchmark
      1. Recording
      2. Replay
      3. Analysis
    3. Profiling
      1. The Flame Graph
      2. Profiling R Code
      3. Profiling a Shiny App
      4. Limitations
    4. Improve Performance
    5. Caching
      1. Basics
      2. Caching a Reactive
      3. Caching Plots
      4. Cache Key
      5. Cache Scope
    6. Other Optimizations
      1. Schedule Data Munging
      2. Manage User Expectations
    7. Summary
  29. Index
  30. About the Author

Product information

  • Title: Mastering Shiny
  • Author(s): Hadley Wickham
  • Release date: April 2021
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492047384