Skip to content

Commit

Permalink
Update the default version / baseline version of webr to v0.2.0 (#24)
Browse files Browse the repository at this point in the history
* Update the version of webr to v0.2.0

* Bump extension version

* Update note on installing package
  • Loading branch information
coatless authored Aug 17, 2023
1 parent 4b49f79 commit 265c215
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion _extensions/webr/_extension.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: webr
title: Embedded webr code cells
author: James Joseph Balamuta
version: 0.2.1
version: 0.3.0
quarto-required: ">=1.2.198"
contributes:
filters:
Expand Down
18 changes: 11 additions & 7 deletions _extensions/webr/webr-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@
// Initialize webR
await globalThis.webR.init();

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

// Capture output data from evaluating the code
const result = await webRCodeShelter.captureR(codeToRun, {
withAutoprint: true,
captureStreams: true,
captureConditions: false,
env: webR.objs.emptyEnv,
captureConditions: false//,
// env: webR.objs.emptyEnv, // maintain a global environment for webR v0.2.0
});

// Start attempting to parse the result data
Expand All @@ -106,16 +106,20 @@

// Output each image stored
msgs.forEach(msg => {
if (msg.type === "canvasExec") {
if (!canvas) {
// Determine if old canvas can be used or a new canvas is required.
if (msg.type === 'canvas'){
// Add image to the current canvas
if (msg.data.event === 'canvasImage') {
canvas.getContext('2d').drawImage(msg.data.image, 0, 0);
} else if (msg.data.event === 'canvasNewPage') {
// Generate a new canvas element
canvas = document.createElement("canvas");
canvas.setAttribute("width", 2 * {{WIDTH}});
canvas.setAttribute("height", 2 * {{HEIGHT}});
canvas.style.width = "700px";
canvas.style.display = "block";
canvas.style.margin = "auto";
}
Function(`this.getContext("2d").${msg.data}`).bind(canvas)();
}
});

Expand Down
2 changes: 1 addition & 1 deletion _extensions/webr/webr-init.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
}

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

// Populate WebR options with defaults or new values based on
// webr meta
Expand Down
2 changes: 1 addition & 1 deletion _extensions/webr/webr-serviceworker.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
importScripts('https://webr.r-wasm.org/v0.1.1/webr-serviceworker.js');
importScripts('https://webr.r-wasm.org/v0.2.0/webr-serviceworker.js');
2 changes: 1 addition & 1 deletion _extensions/webr/webr-worker.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
importScripts('https://webr.r-wasm.org/v0.1.1/webr-worker.js');
importScripts('https://webr.r-wasm.org/v0.2.0/webr-worker.js');
5 changes: 4 additions & 1 deletion webr-demo.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ Or, by navigating to the WebR repository:

#### Installing a Package

Installing `ggplot2` may take at least 2 minutes to run.
Installing a package interactively is done using `webr::install()` inside of a `{webr-r}` code cell.

**Note:** Installing `ggplot2` may take at least 2 minutes if COEP & COOP headers are not set.

```{webr-r}
webr::install("ggplot2")
```


#### Using a Package

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

0 comments on commit 265c215

Please sign in to comment.