r-wasm / webr

The statistical language R compiled to WebAssembly via Emscripten, for use in web browsers and Node.
https://docs.r-wasm.org/webr/latest/
Other
805 stars 54 forks source link

Sending dataframe to javascript #402

Closed guillaumechaumet closed 3 months ago

guillaumechaumet commented 3 months ago

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 ?

georgestagg commented 3 months ago

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) [{…}, {…}, {…}, ...]
guillaumechaumet commented 3 months ago

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