You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use elevatr in ShinyLive / webR, a WASM build of R, but curl, as used in httr, is not available (example issue).
However, download.file() is available and can be used as follows (I haven't checked if the CORS proxy is required, but include it as an option just in case:
# CORS proxy function for webR environmentmake_cors_url<-function(url, params=NULL) {
if (!is.null(params)) {
param_string<- paste(
mapply(
function(k, v) paste0(URLencode(k), "=", URLencode(v)),
names(params),
params
),
collapse="&"
)
url<- paste0(url, "?", param_string)
}
paste0("https://corsproxy.io/", URLencode(url))
}
# Apply CORS proxy if neededuse_cors=Tdem_list<- lapply(urls, function(x) {
tmpfile<- tempfile(tmpdir=tmp_dir, fileext=".tif")
# Apply CORS proxy if neededdownload_url<-if(use_cors) make_cors_url(x) elsex# Use download.file with method="internal" for webR compatibility
tryCatch({
download.file(
download_url, tmpfile
)
# Basic check if file exists and has contentif (!file.exists(tmpfile) || file.size(tmpfile) ==0) {
stop(paste("Failed to download from:", x))
}
# Note: We can't get headers like x-amz-meta-x-imagery-sources with base R# So we'll just return the tmpfile without the source attributetmpfile
}, error=function(e) {
stop(paste("Error downloading from:", x, "\nError:", e$message))
})
})
Would it be possible to have fallback support for download.files() rather than httr so that elevatr can be used in a WebR/WASM context?
The text was updated successfully, but these errors were encountered:
I am amenable to including this; however, I don't have the time at the moment to make the addition. If you can submit a PR, with a test for this, I would be happy to merge it in.
I'm trying to use
elevatr
inShinyLive
/webR
, a WASM build of R, butcurl
, as used inhttr
, is not available (example issue).However,
download.file()
is available and can be used as follows (I haven't checked if the CORS proxy is required, but include it as an option just in case:Would it be possible to have fallback support for
download.files()
rather thanhttr
so thatelevatr
can be used in a WebR/WASM context?The text was updated successfully, but these errors were encountered: