webR with Quarto HTML Standalone Document Proof of Concept

Experiments with an Interactive Quarto Document using webR v0.1.0

Author

JJB leaning heavily on webR authors

Demo

Background

The purpose of this document is to explore how WebR can be embedded in a Quarto Document for the purposes of teaching R.

Setup

See the https://github.com/coatless-r-n-d/webR-quarto-demos for source.

Exploration

Next, let’s look at a few features of the language

Linear Regression

We’ll first start with the WebR team’s demo example or the statistician way of saying, “Hello world!”… Aka linear regression:


Retrieving prior objects

Each WebR cell appears to be connected to each other. Thus, we can access the fit outcome:



Mixing active and non-active R code

For if-else statements, we have:

if (...) {
  # Statements for TRUE
} else {
  # Statements for FALSE
}
  • ... denotes a condition (either TRUE or FALSE)
  • If TRUE, then run the statements inside {}
  • Else, FALSE, carry on with your day.

How could we modify temperature to have the if statement print "Hot!"?


Summarize Data

Glancing at data frames yields:


Errors and Warnings



Base graphics

Graphing with base R


More advanced base R graphing…


ggplot2 Graphics

Next, we look at using ggplot2 graphics. By default, the ggplot2 package is not available as it is dependency heavy.

Package installation for `ggplot2` given by `webr::install("ggplot2")` Downloading webR package: cli Downloading webR package: glue Downloading webR package: gtable Downloading webR package: isoband Downloading webR package: rlang Downloading webR package: lifecycle Downloading webR package: MASS Downloading webR package: lattice Downloading webR package: nlme Downloading webR package: Matrix Downloading webR package: mgcv Downloading webR package: farver Downloading webR package: labeling Downloading webR package: colorspace Downloading webR package: munsell Downloading webR package: R6 Downloading webR package: RColorBrewer Downloading webR package: viridisLite Downloading webR package: scales Downloading webR package: fansi Downloading webR package: magrittr Downloading webR package: utf8 Downloading webR package: vctrs Downloading webR package: pillar Downloading webR package: pkgconfig Downloading webR package: tibble Downloading webR package: withr Downloading webR package: ggplot2