webR with Quarto HTML Standalone Document Proof of Concept
Experiments with an Interactive Quarto Document using webR v0.1.0
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.
- WebR Website: https://docs.r-wasm.org/webr/latest/
- WebR GitHub: https://github.com/r-wasm/webr/
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 (eitherTRUE
orFALSE
)- 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.