-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supported packages? #11
Comments
Yes that's right, the packages that work have been precompiled for WASM. Many R packages require a working C compiler to install from source, and I don't think it's going to be reasonably possible to have a full build toolchain working in the browser, so distributing pre-built WASM binaries is probably the next best thing. It's not well documented, but there's a repo at https://github.com/georgestagg/webr-ports where I have been putting pre-compiled versions of R packages (you can see a list by looking in the My own process for building R packages has been to install them from source into a new and empty R library path by using the The result is a directory containing a single installed R package, along with any libraries built for WASM. I then use Emscripten's I have written a script to take a URL pointing to an R source package and then built it using the process above, it's at https://github.com/georgestagg/webr-ports/blob/main/scripts/install_from_URL.sh. If you'd like to give it a go, you'll need to:
Not all R packages are going to just compile cleanly like that, and for those packages Hopefully in future this can all be streamlined, simplified and documented properly, but for the moment it at least seems to work. I've leave the issue open to remind myself that the process needs work. |
Would you please clarify further how one can install packages from the R packages repo you discussed above. It was my understanding from reading what you wrote that if I try and type into the REPL in webR to install a package that you’ve put into the repo: (e.g. install.packages(‘tidyr’)) that webR would default to try and pulling that package from your package repository. However, when I try typing the above command in the REPL, webR just seems to hang. Fyi. Thanks! |
Running something like Tidyr was probably not the best example, though. At the moment loading packages is handled through hard coded lookups for what other packages are required and I had missed tidyr. I've updated the list so that running
That particular issue should go away once we've patched the internet R module and created a more CRAN like repository. Then we could load packages within webR itself and it will handle the dependencies better. Saying all that, I'm unsure why it was hanging for you. Sometimes the browser will seem to hang for a little while when loading, this is a consequence of running webR on the main thread and should not become a problem when #17 is complete. The hang should not last too long, though. If it continues to happen, please check the browser console with dev tools (F12, usually) and let me know if there are any console error messages from a crashing webR. |
Regarding hangs, I've noticed that the current dev version of webR hangs if I run That said, the released webR REPL doesn't seem to suffer from this particular hang, so this may be something else. |
Thanks, with the new release, I’m able to load up tidyr fine. I wasn’t aware of the need to clear my cache to reinstall a new release— maybe something helpful to put into the future readme file. I’m also a novice to web page work so didn’t know about developer tools. I enabled that option now on my Mac for Safari; seems a bit more of hassle (need to be hardwire iPad to Mac) to use developer tools on a webpage on iPad. However, I found a very useful free replacement app that seemed to accomplish the same thing “Web Inspector” of the Apple App Store. Fyi, P.S. |
I was able to install emscripten as you suggested successfully on my MAC and created a separate folder on my Mac and complied webR in there mimicking the docker environment. I then tried to use your install_from_URL.sh script from the webR-ports site on a test package, and it seemed to initially compile that package well until it hit an error in the shell script: From reading the emscripten website, file_packager.py is supposed to be part of the emscripten sdk but wasn't in my emscripten directory for some reason. I therefore copied the raw file_packager.py code from the emscripten website and tried again to compile a test package from a URL with the install_from_URL shell script, but for some reason having that python script in the proper directory didn't fix the problem and let the compiler use the file_packager command. I tried just running the file_packer.py from python3, and the python script itself seemed to throw some errors (despite being copied directly from emscripten's website). Any thoughts of what I might be doing run with compiling R package on my Mac for use by webR? I think I'm making progress and would appreciate any suggestions at your convenience. Thanks, |
We'll support building packages through https://github.com/lionel-/webr-repo/, but this may require a few changes to the webR build system before, which are planned soon. Currently busy with other things. |
Okay, thanks for letting me know, @lionel-.' Will look forward to those changes. Sincerely, |
@georgestagg and @lionel- , I was able to get emscripten working on my Mac and was able to use the install_from_URL.sh script to create two .js files in the dist directory on my computer as I believe George described in the steps earlier. The package I chose to try and build for webR was the "gridExtra" package. I had hoped that all I would need to do would be to use the webR "upload file" option to the emscripten file system and upload those two packages into the same library path as the other pre-installed packages (e.g. .libPaths() = "/usr/lib/R/library" referencing the emscripten file system on webR). However, it didn't seem that simple-- webR didn't recognize the gridExtra package despite making a gridExtra named folder in the appropriate /usr/lib/R/library path and putting the two gridExtra .js files that I created into it). I re-read George's instruction above and it seems that instead the "library()" function on webR only looks for webR pre-installed packages or packages stored at the webR-ports repo. It looked like George suggested if I wanted to try out package I tried to build for webR using the install_from_URL.sh script that I would need to go into the webR.js file and change the package URL variable there to point to where I stored the newly created package. Unfortunately, as a novice programmer, I don't yet understand how to actually modify the webR.js file on my computer/browser nor how to put the newly created package at a URL location to point the modified webR.js file to. From my reading it looks like browser can point to files in addition to to web address. Thus, could I instead put the file path for the new packages I built on my local computer and change the webR.js file to point to that file path instead of a location on the internet (i.e. URL = "file:///Users/name/Desktop/gridExtra" if on desktop or perhaps even URL = "file:///usr/lib/R/library" to emscripten directory on webR itself)? If so, if you could explain to me how to actually change the webR.js file loaded on my machine (desktop or iPad), I would point webR.js to those locations and test out the new package (gridExtra). My only other concern is that when I look in the directories of the webR-port packages, they seem to have multiple folders in them-- not solely a package.js and data.js package that install_from_URL.sh produces. Is everything needed to have webR use the newly build packages in the newly created package.js and data.js files created from install_from_URL.sh? If these are things I can learn to do as a novice, I'm glad to help out and do the legwork in trying to build multiple R packages with the install_from_URL.sh script and test them out in webR and let you know how they work and send the ones to you that do work. Please let me know at your convenience. Here is a link to the gridExtra files I created on my Mac from the install_from_URL.sh script (untested for the reasons mentioned above): https://www.dropbox.com/sh/lca00logk8imznl/AABVrb7gE5bvtTVX3iJGDTZoa?dl=0 Thanks, |
@georgestagg & @lionel- , I figured out how to create a simple webserver using python's http.server on my Mac and iPad so that I could continue to try and install and test out new R packages for webR. As a novice web developer, I didn't previously realize that my web browser client isn't allowed to fetch new R packages that I've built and stored on my local computer and that I need to fetch those new packages from a server somewhere (which I think is what you meant by your instructions above to point webR.js line to "web space" somewhere. The neat thing is that once I figured out how to do this, I realized that the built webR distribution is all javascript, html and web assembly so can be easily transferred to other servers to run it and does not need to be rebuilt. Here's the steps I took in case other novice web developers want to try installing webR and try adding new R packages to webR on their system:
Once I did all of those steps, I just needed to put the webR "dist" directory from step 1 (which also contained the "pkgdist" subdirectory from step 2) into the default directory for my webserver (e.g. for Debian linux: /var/www/html), start my local webserver (e.g. python3 -m http.server 8080), and then connect from my local machines web browser to my local webserver via local host (e.g. in the URL bar of Safari: http://localhost:8080/) and it worked! (I did need additionally need to chmod grant permissions to execute all of the "dist" files when running the server from Linux although didn't need to do that from Terminal on my Mac). After testing out this process on my Mac (and porting the new 'gridExtra' R package to webR on my Mac running a local server), I transferred the "dist" directory I had built to my iPad which also worked well and ran webR and the new 'gridExtra' R package I ported (I run Debian Linux on my iPad Pro using the sideloaded UTM app [QEMU port] which I used as my server, and then connected to that server with native Mobile Safari using "split screen" mode. I've attached a snapshot of what that looks like running on my iPad. Notably, I can run R on Linux via UTM on my iPad; however, my interest in webR is that it runs at native speed (or almost-- using wasm) which is much faster than R on Linux through UTM's QEMU emulator. I'll continue now to try and test and port other R packages to webR and would be happy to let the webR team know which ones ported well. |
Dear All, mainly @georgestagg & @lionel- , Can we have persistent storage from the Emscripten virtual file system? |
We lost package loading in a recent refactor, sorry about that. It will be coming back soon, certainly before the first versioned release.
Not right now, but I believe it is possible to persist storage using Emscripten's support for |
@georgestagg and @lionel- |
@georgestagg and @lionel- |
A PR to xmlhttprequest-ssl fixing the binary data issue (#11) has been accepted and a new package published to npm. As such, use of my temporary fork has been removed.
@georgestagg, follow-up question on the "install_from_URL.sh" file regarding the Makevars file it creates I was able to get the original docker file from the original repository working and tried building some more webR packages with the install_from_URL.sh. One in particular I've been trying to build is the R curl package as it is needed by the R jsonlite package to be able to access web APIs. However, I was initially puzzled due to the installation failing with the R curl package configure file giving me an error after decompressing the R curl package that it could not find libcurl or its headers despite my double checking that I appropriately had libcurl and its headers installed. I also verified that there wasn't a problem with the R curl package itself as I successfully installed it on my Mac without emscription by using solely:
I then looked further into the the actual R curl package's .configure file and noted that it finds the compiler and flags by these statements:
The R curl package .configure file then goes on to test the configuration by the following:
The next line then goes on to print the following error if $R_CONFIG_ERROR=1:
Since when I ran the install_from_URL.sh script form the webR-ports I cloned into the prior repository's docker image, it appropriately identified the libcurl dir and its headers directory before displaying the above error, I suspect that I'm actually seeing that error not because of the R curl package configure script finding libcurl or its headers but because of a problem with the R curl package configure script finding and/or using the emscripten compiler or its flags which are tested in the R curl package configure scripts test statement that I listed previously. In fact, when I use a standard
of the R curl source package from my Mac desktop without emscripten or the install_from_URL.sh script, it works, and I'm able to echo display all of the required environmental variables (i.e.:
However, when I echo display those same variables in the docker environment in which I run the install_from_URL.sh, I noticed that the:
variable isn't set to anything. When I then open and read the install_from_URL.sh script, I notice that the install_from_URL.sh script itself sets environmental variables as follows:
But CPPFLAGS does not seem to be set by the install_from_URL.sh script Also no
environmental variable seems to be set in the docker image; thus I suspect that CFLAGS would also not get set with the script either and might cause the .configure file in the R curl package to trigger and error and the build to fail. I suspected that
was intended to be the same as the environmental variable
and thus in the docker environment did:
Then added to the install_from_URL.sh script:
However, that did not work either. Thus, in order to try and compile the R curl package to .wasm with the install_from_URL.sh script: 1a) Do I need to add a line in the install_from_URL.sh to set CPPFLAGS to something? 1b) If so, what would I set CPPFLAGS to? 2a) Do I need to change what CFLAGGS is set for in install_from_URL.sh? I hope this post was an appropriate issue to raise and ask and as a novice Bash user, I did my due Thanks! |
Firstly, I should mention that While Now, regarding the R curl package. The fundamental issue is that the package links to the libcurl library to work, but you cannot simply link to the libcurl installed on your machine with the Emscripten compiler, because it has not itself been compiled for WASM. In fact, all the system prerequisites for a package need to also have been compiled for WASM. Emscripten provides several of these libraries for us, but as far as I am aware not libcurl. In fact, it is my understanding that under the current WebAssembly specification the libcurl library can probably never be compiled directly for WASM, because the browser WASM runtime has no direct access to network sockets. There are tricks one can do with Emscripten, but they require communicating over websockets rather than standard HTTP, or external tools such as proxy servers. One possible solution is to write an entirely new libcurl shim that converts libcurl API calls to browser based Without a version of libcurl for WASM, the R curl package cannot be compiled. |
Thank you for explaining that, @georgestagg, that all makes sense. As I novice, I misunderstand that basic principle that one must link libraries already compiled to WASM and therefore is not as simple as just linking to libraries already installed on one's machine. It thus seems that the process of compiling R packages to WASM with install_from_URL.sh is not something most novices will be successful at, and I will patiently keep an eye out for new packages on the GitHub repo when you are able to develop and release them. |
I'm going to close this, since the original question has been answered. For anyone dropping by, you can view the currently supported packages in webR using the command,
Further information about the webR package build process will be added in future to the documentation, once the process is a little more developed and stable. |
@georgestagg, Appreciate your thoughts. |
For webR, R itself has been patched to use JavaScript XHR for However, the Browser API only provides a small subset of the capabilities of the curl project, so using the same trick largely does not work. At most only a partial implementation of curl could be made. See posit-dev/r-shinylive#31 (comment) for a comment I've written with a bit more detail. |
Thanks, @georgestagg, for explaining-- that makes sense. I asked because one of the brilliant developers in our iPad Codea lua community figured out how to make a WebR - JS- Codea lua bridge that works well on the iPad 😊 (see attached screenshot). Such a bridge allows novice users like myself to combine the statistical and plotting power of R with the ease of scripting/other GUI/graphic creation in lua on a mobile device, and I'm attempting to make small useful projects that involve analyzing downloaded datasets. |
hi @georgestagg I played around with the demo and it's fairly impressive to see R running entirely within the browser. I tried loading a few packages, like dplyr, ggplot and a few others, and it seems there is some limitation as to what packages are currently supported. How do packages support work exactly? Are they precompiled and therefore only a specific set is available? What is the work required to add new packages?
The text was updated successfully, but these errors were encountered: