-
Notifications
You must be signed in to change notification settings - Fork 74
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
How to bundle pre-installed R packages with WebR's WASM for client-side usage without additional installation? #511
Comments
I try to do almost exactly the same thing into an Electron application, as described in #510.
I assume you just need to write the relevant JS code and automatically run it on page load, the documentation link above contains an example you can follow. In my case, although successfully mounting the VFS, for a reason that I don't fully understand, loading the package ends with an error. |
@dusadrian is correct, the method he describes is the way to go, with documentation here. First, on your machine use the rwasm::add_pkg("ggplot2")
rwasm::make_vfs_library() (Note that you will need to follow the Getting Started instructions before these R functions will work.) The resulting files, written to the Then, in the client browser at load time, use webr::mount(mountpoint = "/my-library", source = "https://example.com/library.data")
.libPaths(c(.libPaths(), "/my-library"))
library(ggplot2) |
This is decreasing the whole bundle size and loading time a lot in my case!
If you want, I can split the points you find relevant into different issues. |
That is interesting, I would also like to know. For the second point, I guess that is not possible automatically. But you can re-create those packages from their original sources, pruning them yourself. Linked to that, you can fork those packages on GitHub, and use the If the packages are added to the VFS library, there should be no real bottleneck loading them. What I do, when doing calculations that require significant time, is to cover the screen with a div showing a message (in your case "Loading packages in the R environment...") and use |
Since For the second point, I hoped for a simpler way, but yeah that's probably how I will end up doing it. I even consider something more brutal to drastically reduce the app size. A lot of packages I need require the whole tidyverse... But I know that only a tiny fraction of each tidyverse package is at work for my use cases. So I thought I could: 1-Create an exhaustive E2E test suit covering all use cases for my apps I have no idea what benefit would result with such approach. But I think that if we want to deploy smaller webr apps, we should have something similar to tree shaking for R. The language itself does not make it easy to implement, especially because of the (amazing) tidy eval feature. @georgestagg any thoughts on this? I would gladly explore the topic further, but maybe you already have a better plan for handling this? PS: showing a message and a spinner was indeed my first approach to keep users waiting. But in case of very slow network, people had no clue if something was happening or if the app was stuck despite the message. Having a real progress bar was necessary (unless I can drastically reduce the app size :D) |
Can you show me an example? webR v0.4.1+ should transparently mount compressed packages produced using
For certain {rwasm} functions, a rwasm::make_vfs_library(..., strip = c('doc', 'vignettte', 'examples', 'html', ...)) to remove a list of named subdirectories of R packages as the package library is created. We do not have tree-shaking as of yet, but this is a crude way to reduce package size.
A list of package references can be given in the rwasm::add_pkg("cli", remotes=c("r-lib/[email protected]"))
Tree shaking is something I am interested in, but I don't yet have a clear idea of what the path would be to making this work well. I would say it's a goal, but a long-term one. For the moment, we're making do with the naive method shown above of directly stripping out large package directories.
The limiting factor with loading a combined package repository in the form of a single VFS image is the browser download, and there is currently no feedback provided by webR as the data is streamed in, sorry about that. In principle Emscripten can support this, and there are Wasm apps that listen to the events shared by Emscripten as files are downloaded and show a progress bar, so it is possible for a future improvement to webR. For the moment, the only thing I can think of would be to build to multiple VFS images, mount several package libraries, and show updates after each one is downloaded. It's a hack, but it might be worth the additional complexity if your package library is particularly large. |
Thanks for your work.
I would like to bundle pre-installed R packages, such as ggplot2, along with WebR's WASM so that they can be directly used on the client-side without requiring additional installation of R packages.
How can I package the already installed R packages along with WebR's WASM, ensuring that the client can use the R packages (like ggplot2) without the need for extra installation steps? Specifically, I am interested in embedding both the R environment and the necessary R packages in such a way that they are available immediately upon loading in the client's browser.
The text was updated successfully, but these errors were encountered: