From 4e1045dc0ce560d425ab28cb4a3c9bfd50f685a7 Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Thu, 30 Nov 2023 08:59:53 -0600 Subject: [PATCH 1/4] Bump shinylive web assets to 0.2.3 (#38) --- R/version.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/version.R b/R/version.R index 8bc70b8..3d809da 100644 --- a/R/version.R +++ b/R/version.R @@ -1,3 +1,3 @@ # This is the version of the Shinylive assets to use. -SHINYLIVE_ASSETS_VERSION <- "0.2.1" +SHINYLIVE_ASSETS_VERSION <- "0.2.3" SHINYLIVE_R_VERSION <- as.character(utils::packageVersion("shinylive")) From 55611160b8e26659c468ee94265b4b4d46e97fd8 Mon Sep 17 00:00:00 2001 From: Doug Kelkhoff <18220321+dgkf@users.noreply.github.com> Date: Thu, 30 Nov 2023 10:05:10 -0500 Subject: [PATCH 2/4] Increasing download timeout (#30) --- R/assets.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/assets.R b/R/assets.R index df47270..f1f35bd 100644 --- a/R/assets.R +++ b/R/assets.R @@ -36,6 +36,11 @@ 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") message("Unzipping to ", dir, "/") From 11aeb30ed55e9213f12602e18d94c3dd4d69978d Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Thu, 30 Nov 2023 10:53:37 -0500 Subject: [PATCH 3/4] feat: Use `{httr2}` to download assets to avoid timeout and give a progress bar (#39) --- DESCRIPTION | 2 +- NEWS.md | 2 ++ R/assets.R | 24 ++++++++++++++---------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index cba6032..377a592 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,6 +20,7 @@ Imports: archive, brio, fs, + httr2 (>= 1.0.0), jsonlite, progress, rappdirs, @@ -27,7 +28,6 @@ Imports: tools Suggests: plumber, - httr, spelling, testthat (>= 3.0.0) Config/Needs/website: tidyverse/tidytemplate diff --git a/NEWS.md b/NEWS.md index 078d6d1..093a58c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/R/assets.R b/R/assets.R index f1f35bd..77e87e5 100644 --- a/R/assets.R +++ b/R/assets.R @@ -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( { @@ -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) @@ -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 } From 53903872d1cca3578f17d56c0d7537c6f6148fda Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Thu, 30 Nov 2023 11:16:48 -0500 Subject: [PATCH 4/4] feat: Use `httpuv::runStaticServer(dir)` instead of `{plumber}` (#40) --- DESCRIPTION | 4 ++-- NEWS.md | 1 + R/export.R | 12 ++++-------- README.md | 9 +++------ local/shiny-apps/issue-029-r/app.R | 22 ++++++++++++++++++++++ man/export.Rd | 9 +++------ 6 files changed, 35 insertions(+), 22 deletions(-) create mode 100644 local/shiny-apps/issue-029-r/app.R diff --git a/DESCRIPTION b/DESCRIPTION index 377a592..492482c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: shinylive Title: Run 'shiny' Applications in the Browser -Version: 0.1.0.9000 +Version: 0.1.0.9001 Authors@R: c( person("Barret", "Schloerke", , "barret@posit.co", role = c("aut", "cre"), @@ -27,7 +27,7 @@ Imports: rlang, tools Suggests: - plumber, + httpuv (>= 1.6.12), spelling, testthat (>= 3.0.0) Config/Needs/website: tidyverse/tidytemplate diff --git a/NEWS.md b/NEWS.md index 093a58c..110935d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # shinylive (development version) +* Use `{httpuv}` to serve static folder instead of plumber. (#40) * Use `{httr2}` to download assets from GitHub releases. (@dgkf #30, #39) # shinylive 0.1.0 diff --git a/R/export.R b/R/export.R index 1c82ce8..114bfc2 100644 --- a/R/export.R +++ b/R/export.R @@ -1,7 +1,7 @@ #' Export a Shiny app to a directory #' #' This function exports a Shiny app to a directory, which can then be served -#' using `plumber`. +#' using `httpuv`. #' #' @param appdir Directory containing the application. #' @param destdir Destination directory. @@ -21,11 +21,8 @@ #' export(app_dir, out_dir) #' #' # Serve the exported directory -#' if (require(plumber)) { -#' library(plumber) -#' pr() %>% -#' pr_static("/", out_dir) %>% -#' pr_run() +#' if (require(httpuv)) { +#' httpuv::runStaticServer(out_dir) #' } export <- function( appdir, @@ -155,8 +152,7 @@ export <- function( verbose_print( "\nRun the following in an R session to serve the app:\n", - " library(plumber)\n", - " pr() %>% pr_static(\"/\", \"", destdir, "\") %>% pr_run()\n" + " httpuv::runStaticServer(\"", destdir, "\")\n" ) invisible() diff --git a/README.md b/README.md index a1428e4..256ae63 100644 --- a/README.md +++ b/README.md @@ -49,10 +49,7 @@ shinylive::export("myapp", "site") Then you can preview the application by running a web server and visiting it in a browser: ``` r -library(plumber) -pr() %>% - pr_static("/", "site/") %>% - pr_run() +httpuv::runStaticServer("site/") ``` At this point, you can deploy the `site/` directory to any static web hosting service. @@ -191,7 +188,7 @@ shinylive_lua |> Export a local app to a directory and run it: ```r -library(plumber) +library(httpuv) # >= 1.6.12 pkgload::load_all() # Delete prior @@ -199,5 +196,5 @@ unlink("local/shiny-apps-out/", recursive = TRUE) export("local/shiny-apps/simple-r", "local/shiny-apps-out") # Host the local directory -pr() %>% pr_static("/", "local/shiny-apps-out") %>% pr_run() +httpuv::runStaticServer("local/shiny-apps-out/") ``` diff --git a/local/shiny-apps/issue-029-r/app.R b/local/shiny-apps/issue-029-r/app.R new file mode 100644 index 0000000..3568fd2 --- /dev/null +++ b/local/shiny-apps/issue-029-r/app.R @@ -0,0 +1,22 @@ +library(shiny) + +ui <- fluidPage( + selectInput("dataset", "Choose a dataset", c("pressure", "cars")), + selectInput("column", "Choose column", character(0)), + verbatimTextOutput("summary") +) + +server <- function(input, output, session) { + dataset <- reactive(get(input$dataset, "package:datasets")) + + observeEvent(input$dataset, { + freezeReactiveValue(input, "column") + updateSelectInput(inputId = "column", choices = names(dataset())) + }) + + output$summary <- renderPrint({ + summary(dataset()[[input$column]]) + }) +} + +shinyApp(ui, server) diff --git a/man/export.Rd b/man/export.Rd index 1703297..953a998 100644 --- a/man/export.Rd +++ b/man/export.Rd @@ -24,7 +24,7 @@ the directory are printed to stdout. } \description{ This function exports a Shiny app to a directory, which can then be served -using \code{plumber}. +using \code{httpuv}. } \examples{ \dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} @@ -35,11 +35,8 @@ out_dir <- tempfile("shinylive-export") export(app_dir, out_dir) # Serve the exported directory -if (require(plumber)) { - library(plumber) - pr() \%>\% - pr_static("/", out_dir) \%>\% - pr_run() +if (require(httpuv)) { + httpuv::runStaticServer(out_dir) } \dontshow{\}) # examplesIf} }