Skip to content

Commit 265c215

Browse files
authored
Update the default version / baseline version of webr to v0.2.0 (#24)
* Update the version of webr to v0.2.0 * Bump extension version * Update note on installing package
1 parent 4b49f79 commit 265c215

6 files changed

+19
-12
lines changed

_extensions/webr/_extension.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: webr
22
title: Embedded webr code cells
33
author: James Joseph Balamuta
4-
version: 0.2.1
4+
version: 0.3.0
55
quarto-required: ">=1.2.198"
66
contributes:
77
filters:

_extensions/webr/webr-editor.html

+11-7
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@
7979
// Initialize webR
8080
await globalThis.webR.init();
8181

82-
// Setup a webR canvas
83-
await webR.evalRVoid("canvas(width={{WIDTH}}, height={{HEIGHT}})");
82+
// Setup a webR canvas by making a namespace call into the {webr} package
83+
await webR.evalRVoid("webr::canvas(width={{WIDTH}}, height={{HEIGHT}})");
8484

8585
// Capture output data from evaluating the code
8686
const result = await webRCodeShelter.captureR(codeToRun, {
8787
withAutoprint: true,
8888
captureStreams: true,
89-
captureConditions: false,
90-
env: webR.objs.emptyEnv,
89+
captureConditions: false//,
90+
// env: webR.objs.emptyEnv, // maintain a global environment for webR v0.2.0
9191
});
9292

9393
// Start attempting to parse the result data
@@ -106,16 +106,20 @@
106106

107107
// Output each image stored
108108
msgs.forEach(msg => {
109-
if (msg.type === "canvasExec") {
110-
if (!canvas) {
109+
// Determine if old canvas can be used or a new canvas is required.
110+
if (msg.type === 'canvas'){
111+
// Add image to the current canvas
112+
if (msg.data.event === 'canvasImage') {
113+
canvas.getContext('2d').drawImage(msg.data.image, 0, 0);
114+
} else if (msg.data.event === 'canvasNewPage') {
115+
// Generate a new canvas element
111116
canvas = document.createElement("canvas");
112117
canvas.setAttribute("width", 2 * {{WIDTH}});
113118
canvas.setAttribute("height", 2 * {{HEIGHT}});
114119
canvas.style.width = "700px";
115120
canvas.style.display = "block";
116121
canvas.style.margin = "auto";
117122
}
118-
Function(`this.getContext("2d").${msg.data}`).bind(canvas)();
119123
}
120124
});
121125

_extensions/webr/webr-init.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
}
8080

8181
// Retrieve the webr.mjs
82-
import { WebR } from "https://webr.r-wasm.org/v0.1.1/webr.mjs";
82+
import { WebR } from "https://webr.r-wasm.org/v0.2.0/webr.mjs";
8383

8484
// Populate WebR options with defaults or new values based on
8585
// webr meta
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
importScripts('https://webr.r-wasm.org/v0.1.1/webr-serviceworker.js');
1+
importScripts('https://webr.r-wasm.org/v0.2.0/webr-serviceworker.js');

_extensions/webr/webr-worker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
importScripts('https://webr.r-wasm.org/v0.1.1/webr-worker.js');
1+
importScripts('https://webr.r-wasm.org/v0.2.0/webr-worker.js');

webr-demo.qmd

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ Or, by navigating to the WebR repository:
5151

5252
#### Installing a Package
5353

54-
Installing `ggplot2` may take at least 2 minutes to run.
54+
Installing a package interactively is done using `webr::install()` inside of a `{webr-r}` code cell.
55+
56+
**Note:** Installing `ggplot2` may take at least 2 minutes if COEP & COOP headers are not set.
5557

5658
```{webr-r}
5759
webr::install("ggplot2")
5860
```
5961

62+
6063
#### Using a Package
6164

6265
Once `ggplot2` is loaded, then use the package as normal.

0 commit comments

Comments
 (0)