-
Notifications
You must be signed in to change notification settings - Fork 18
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
Fetching external data via httr, Curl not available #31
Comments
I always thought jsonlite used httr behind the scenes for remote files / json apis, so now I'm even unfamiliar in R. The below works though
|
The The issue is that opening raw network sockets is not permitted from the WebAssembly sandbox. As such, it's not reasonably possible to compile Nevertheless, the base R distribution in webR has been modified to handle calls to data_url <- "https://media.githubusercontent.com/media/datablist/sample-csv-files/main/files/customers/customers-100.csv"
download.file(data_url, "data.csv")
readLines(url(data_url))
read.csv(data_url) It might be possible to fetch the external data you require these functions. This is most likely why Technically, some methods can enable network connections from Wasm, but AFAIK they rely on one of two schemes:
The first method is not a reasonable solution for a project like webR or Shinylive, where we aim to provide a self-contained application without supporting servers outside the web browser. The second method can partially work, but Curl is a project with a wide range of features and supports many network protocols. At best, we could perhaps support Curl's HTTP and WS features by converting |
Thank you for the detailed response George! Yes I was sending requests to some other sites and noticed CORs response in the browser. For me I actually only want this to interact with my own API's where CORs would be enabled so that's actually a no issue. I'm brainstorming how I can change my API's around so that they're accessible as just a URL with an api_key or something like that as a query parameter for authentication. I have a lot of small dashboards / shiny apps that just need a little bit of shiny interactivity, often too much for crosstalk to handle, but still pretty basic apps. I imagine shimming some of the libraries from libcurl would be a feature users would want at some point. When I think of webR I see a huge opportunity to replace virtually all of my dashboarding / basic web app needs. Which for years has been a pain at a number of jobs, IT's not interested in spinning up compute for a few shiny apps, and the business isn't invested enough in R to justify any of Posit's products. Even right now with utils download.file and url it might be enough for me to achieve what I'm looking to do as I'm working on my own stack / business. However I guess I could still probably run into some of the same issues if I were working for another company, where now the issue is needing a very specific API endpoint if I want to interact with remote (but likely on the same network) data. Either way really enjoying webR so far! All the above will help me out a lot going forward. |
Just a quick note to keep in mind that, unlike a traditional Shiny app, there are no secrets in a shinylive app! Your entire app's source code, including any API Keys saved within, is viewable from the client side. |
A follow up, which is still fetching data related, and probably makes sense to be here on the r-shinylive vs webr repo. After reading some of the great posts by @ColinFay it looks like one of the best ways to interact with data via shinylive/webr will come from mounting file systems. From webr there are two APIs While So the question I'm trying to get to here is whether from shinylive there might be an option to export an app under Node.js?
I also see that there is an R API from webr to mount a file system in R under Node.js, so maybe this is something under development? As I imagine anyone that gets far enough to launch a webr/shinylive from Node.js would just mount it from Node. At the same time webr isn't and R package, just available on npm with the webr R package being
So I assume the below code chunk exists only when running R from Node? So maybe the above isn't possible an I'd need to write a little bit of Node.js to achieve this.
In the nature of R it'd be nice to do everything from R, but totally understand if that's not the case, either way it's been exciting watching webr/shinylive! |
Hi @scrapeable, Whilst webR can work in a browser and Node, Shinylive has been designed only for use in a web browser. In your example code above there are two separate webR sessions:
They are independent and cannot talk to one another. The correct way to access local file systems from the web browser is by using the JavaScript File System API. However, using this in webR is difficult for deep technical reasons. We plan to support it in the future, in a similar way to I'm going to close this for now, in the interest of keeping things neat and tidy, since we've gone off track from the original issue title. For those coming for information on |
Will webR be able to fetch external data from API's and what not?
I am clearly unfamiliar with WASM, but checking stackoverflow, and asking chatgpt looks like the answer is probably going to be no.
The text was updated successfully, but these errors were encountered: