Skip to content
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

feat: Use {httr2} to download assets to avoid timeout and give a progress bar #39

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ Imports:
archive,
brio,
fs,
httr2 (>= 1.0.0),
jsonlite,
progress,
rappdirs,
rlang,
tools
Suggests:
plumber,
httr,
spelling,
testthat (>= 3.0.0)
Config/Needs/website: tidyverse/tidytemplate
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# shinylive (development version)

* Use `{httr2}` to download assets from GitHub releases. (@dgkf #30, #39)

# shinylive 0.1.0

* Initial CRAN submission.
24 changes: 14 additions & 10 deletions R/assets.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ assets_download <- function(
version = assets_version(),
...,
# Note that this is the cache directory, which is the parent of the assets
# directory. The tarball will have the assets directory as the top-level subdir.
# directory. The tarball will have the assets directory as the top-level
# subdir.
dir = assets_cache_dir(),
url = assets_bundle_url(version)) {
tmp_targz <- tempfile(paste0("shinylive-", gsub(".", "_", version, fixed = TRUE), "-"), fileext = ".tar.gz")
tmp_targz <- tempfile(
paste0("shinylive-", gsub(".", "_", version, fixed = TRUE), "-"),
fileext = ".tar.gz"
)

on.exit(
{
Expand All @@ -36,12 +40,10 @@ assets_download <- function(
)

message("Downloading shinylive assets v", version, "...")

# temporarily increase download timeout for ?utils::download.file guidelines
opts <- options(timeout = 250 * 60 * 2) # expect minimum 0.5 MB/s
on.exit(options(opts))

utils::download.file(url, destfile = tmp_targz, method = "auto")
req <- httr2::request(url)
req <- httr2::req_progress(req)
httr2::req_perform(req, path = tmp_targz)
message("") # Newline after progress bar

message("Unzipping to ", dir, "/")
fs::dir_create(dir)
Expand Down Expand Up @@ -372,6 +374,8 @@ assets_version <- function() {
check_assets_url <- function(
version = assets_version(),
url = assets_bundle_url(version)) {
req <- httr::HEAD(url)
req$status_code == 200
req <- httr2::request(url)
req <- httr2::req_method(req, "HEAD")
resp <- httr2::req_perform(req)
resp$status_code == 200
}
Loading