Closed
Description
The following page used to work with https://webr.r-wasm.org/latest/webr.mjs, now it works only with https://webr.r-wasm.org/v0.4.4/webr.mjs
The error in JavaScript console (following the downloads of all R packages):
my_page.html:46 Uncaught (in promise) TypeError: resolved is not a function
at stubs.<computed> (R.js:1821:29992)
at 005c0856
at 005c0856
at 005c0856
at R.wasm
at R.wasm
at R.wasm
at R.wasm
at R.wasm
at R.wasm
The page:
<html>
<head>
<title>WebR SVG and PNG Plot Download Example</title>
</head>
<body>
<h1>WebR SVG and PNG Plot Download Example</h1>
<p id="loading">Please wait, webR is working on producing a plot...</p>
<p id="link-container"></p>
<div id="svg-container"></div>
<script type="module">
import { WebR } from 'https://webr.r-wasm.org/latest/webr.mjs';
(async () => {
const webR = new WebR();
await webR.init();
await webR.installPackages(['svglite', 'ggplot2']);
await webR.evalRVoid(`
svglite::svglite('/home/web_user/Rplots.svg')
library(ggplot2)
data = data.frame(value = rnorm(100))
p <- ggplot(data, aes(x = value)) + geom_histogram()
print(p)
dev.off()
png('/home/web_user/Rplots.png', width = 800, height = 800, res = 144)
print(p)
dev.off()
`);
const plotData1 = await webR.FS.readFile('/home/web_user/Rplots.svg');
const plotData2 = await webR.FS.readFile('/home/web_user/Rplots.png');
const blob = new Blob([plotData2], { type: 'application/octet-stream' });
const link = document.createElement('a');
link.download = 'Rplots.png';
link.href = URL.createObjectURL(blob);
link.textContent = 'Click to download PNG file';
document.getElementById('link-container').appendChild(link);
const svgText = new TextDecoder().decode(plotData1);
const svgContainer = document.getElementById('svg-container');
svgContainer.innerHTML = svgText;
document.getElementById('loading').remove();
})();
</script>
</body>
</html>
Metadata
Metadata
Assignees
Labels
No labels