webR with Quarto HTML Standalone Document Proof of Concept

Experiments with an Interactive Quarto Document using webR v0.1.0

Author

James J Balamuta; modified by EEH

Background

This is not my work. Forked from and go there to see how this works James J Balamuta: https://github.com/coatless-r-n-d/webR-quarto-demos

This was created by JJB to explore how WebR can be embedded in a Quarto Document for the purposes of teaching R.

Setup

The yaml includes this. Note the webr-setup.html and _webr-setup.qmd` files.

---
title: "the title"
engine: knitr
execute:
  echo: true
  error: true
embed-resources: true
format:
    html: 
      toc: true
      include-in-header: webr-setup.html
editor: source
---

{{< include _webr-setup.qmd >}}

Calling WebR

Use {webr} rather than {r} for your code.

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



Summarize Data

Glancing at data frames yields:


Errors and Warnings



Base graphics

Graphing with base R


More advanced base R graphing…


ggplot2 Graphics

There is an extra step of installing packages that are not part of the base.

CLICK RUN AND WAIT LIKE 1 MINUTE. When you see output, it means it is loaded. Be patient.


Now we can use ggplot2 in the qmd.