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
864 stars 67 forks source link

Can webR open a new html window (e.g. using the "reactable" library")? #248

Closed SugarRayLua closed 3 months ago

SugarRayLua commented 1 year ago

Hi.

Your team continues to do really amazing work with WebR. Now appears to be a very usable IDE!

I also saw that you've added a lot of packages which is very helpful. Specifically, I saw that you added reactable which I've been waiting for since with WebR one cannot open up an X window and thus one is unable to quickly use "View" to see one's dataframe in a convenient spreadsheet view. The reactable library provides some of the same functionality by allowing one to view one's dataframe as an html widget. Although reactable seemed to load up fine on webR, I couldn't get it to open and display a dataframe on my browser (Safari, mobile iOS on iPad).

Command given: library(reactable) reactable(mtcars)

No error or new html window with mtcars dataframe in it displayed.

Fyi.

georgestagg commented 1 year ago

Thanks for reporting this.

The underlying (more general) issue is that utils::browseURL() relies on system(), which is not available for webR.

In theory, the browseURL() function could be shimmed (similar to the suggestion in #262), but things might be made tricky by the fact that the HTML content only exists on the virtual filesystem. It will need some thought.

SugarRayLua commented 1 year ago

Thank you for looking into this issue and considering a remedy. :-)

timelyportfolio commented 11 months ago

Another potential (but inelegant) approach to htmlwidgets with webR would be to let R instantiate/construct the widget and then JS (with correct dependencies loaded) build through htmlwidgets.js. Here is an old post demonstrating the approach (long before webR). I'll try to build out a little example with reactable and webR.

timelyportfolio commented 11 months ago

Using a little easier approach than the post, here is an example how we might include reactable htmlwidget from webR. The most difficult part is manually handling/adding the dependencies. These should live in the webR virtual file system, so I am wondering if we could use/add from there. Also reminds me of https://github.com/ramnathv/htmlwidgets/issues/249.

example on stackblitz

image

georgestagg commented 3 months ago

Fixed in #449. Tracking browseURL() in #295.

SugarRayLua commented 3 months ago

Thank you very much! 😊