Open
Description
Hi,
First of all, thanks again for your wonderful work. 500 students are using it in the lessons of ggplot2 uncharted and gave awesome feedback. 🙏🙏🙏
I currently manage to show
- console output from
print()
statements and - errors
successfully.
Here is some pseudo code for my runRCode
function. setConsoleContent
allows to update my internal state that then shows the error/logs in the console.
const runRCode = async (code: string) => {
const canvas = canvasRef.current;
const ctx = canvas.getContext("2d");
try {
const shelter = await new webR.Shelter();
const capture = await shelter.captureR(code);
if (capture.images.length > 0) {
const img = capture.images[capture.images.length - 1];
... draw the img in the canvas
}
// Deal with print statements: ✅
setConsoleContent(capture.output);
// Deal with warnings: need to translate the R warning in a string ❌
..... ? toJS() ??
shelter.purge();
} catch (error: unknown) {
// Handle any JavaScript errors that occur during R execution ✅
const errorMessage =
error instanceof Error ? error.message : "Unknown error";
setConsoleContent([
{
type: "stderr",
data: errorMessage,
},
]);
}
};
But after hours trying, I cannot manage to get the warnings issued by R. I understand they are available in a "Proxy" object. I've tried to extract it with many methods like toJS()
but never managed to get a string from it.
I've spend forever reading your doc, especially this page but did not manage to make it work.
I would be genuinely grateful for any tip on this topic.
Once again, thanks so much for your work! 🙏
Metadata
Metadata
Assignees
Labels
No labels