r-wasm / webr

The statistical language R compiled to WebAssembly via Emscripten, for use in web browsers and Node.

Home Page:https://docs.r-wasm.org/webr/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sending dataframe to javascript

guillaumechaumet opened this issue · comments

I have questions about how to format a R dataframe to a nested array format compatible with datatables.net or tabulator e.g.:
[
{
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
},
...
]

There is in the webr documentation, a 'toD3(' example but this function seems to be not available anymore.

toObject function produces a list with a 'names' array and a 'values' array with nested arrays 0, 1, 2, 3 ... for each column.

Is it possible to have the return of "toD3" function ?

Which version of webR are you using? From webR v0.3.0 you should be able to do something along the lines of:

> const cars = await webR.evalR('mtcars');
> await cars.toD3();
(32) [{}, {}, {}, ...]

my bad. It's a npm issue not upgrading webr stuck in 2.2
Thanks for your response