Issue: webr.evalR() not capturing R output into result.obj #520
Closed
manojkumaryejjala
started this conversation in
Ideas
Replies: 1 comment
-
Closing in favour of #521. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi All,
The webr.evalR() function is not capturing the text output of R code into the result.obj property of the returned promise. While the R code executes (as confirmed by output appearing in the webr-main.ts logs), result.obj consistently returns undefined. This prevents the retrieval and display of R output within the browser.
Browser: Chrome 133.0.6943.142
Operating System: Windows 11, Version 24H2
WebR Version: https://webr.r-wasm.org/latest/webr.mjs
HTML:
<title>WebR Test</title> <script type="module" src="script.js"></script> <textarea id="code" rows="10" placeholder="Enter R code here..."></textarea>Run
JavaScript:
import { WebR } from "https://webr.r-wasm.org/latest/webr.mjs";
let webr = null;
document.addEventListener('DOMContentLoaded', async () => {
const output = document.getElementById('output');
webr = new WebR();
await webr.init();
});
3. Steps to Reproduce:
Create an HTML file with the provided structure.
Create a JavaScript file with the provided code.
Include the webr.mjs file from the specified CDN.
Open the HTML file in the specified browser.
Enter R code in the textarea (e.g., 1 + 1, print("test"), rnorm(10,5,1)).
Click the "Run" button.
Observe the developer console and the output area.
4. Expected Behavior:
The output of the R code should be captured in the result.obj property and displayed in the output div.
The R code executes (as evidenced by output appearing in the webr-main.ts logs, e.g., webr-main.ts:318 [1] 2).
The result.obj property consistently returns undefined.
The output area displays "No output" or an error message if an R error occurs.
6. Additional Information:
I have tried using capture.output() and print() within the R code, but the issue persists.
I have tested with different R commands, including simple arithmetic, print() statements, and numerical data generation (rnorm()), with consistent results.
The issue appears to be related to how WebR captures the output of webr.evalR().
The toArray() function also does not return useable data.
I have tried several different versions of my javascript file, and html file.
I have tried using different browsers.
I have tested on multiple computers.
7. Console Log Output:
(Paste the console log output here, including the R result, Keys of result, and result.obj logs.)
webr-main.ts:321 WebR is using
PostMessage
communication channel, nested R REPLs are not available.webr-main.ts:318 [1] 2
script.js:14 R result: Proxy(Object) {obj: {…}, payloadType: 'ptr'}
script.js:15 Keys of result: (2) ['obj', 'payloadType']
script.js:16 result.obj: undefined
script.js:18 No output
8. Request:
Please investigate this issue and provide guidance on how to correctly capture R output using webr.evalR(). If this is a bug, please provide a fix or workaround.
Thank you for your time and assistance.
Beta Was this translation helpful? Give feedback.
All reactions