Skip to content

Commit

Permalink
Merge branch 'main' into rc-v0.1.1
Browse files Browse the repository at this point in the history
* main:
  feat: Use `httpuv::runStaticServer(dir)` instead of `{plumber}` (#40)
  feat: Use `{httr2}` to download assets to avoid timeout and give a progress bar (#39)
  Increasing download timeout (#30)
  Bump shinylive web assets to 0.2.3 (#38)
  • Loading branch information
schloerke committed Dec 1, 2023
2 parents d42ea13 + 5390387 commit a84b8b7
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 28 deletions.
4 changes: 2 additions & 2 deletions 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,
httpuv (>= 1.6.12),
spelling,
testthat (>= 3.0.0)
Config/Needs/website: tidyverse/tidytemplate
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

* Bump shinylive assets dependency to 0.1.1.

* 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

* Initial CRAN submission.
19 changes: 14 additions & 5 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,7 +40,10 @@ assets_download <- function(
)

message("Downloading shinylive assets v", version, "...")
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 @@ -367,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
}
12 changes: 4 additions & 8 deletions R/export.R
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion R/version.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# This is the version of the Shinylive assets to use.
SHINYLIVE_ASSETS_VERSION <- "0.2.2"
SHINYLIVE_ASSETS_VERSION <- "0.2.3"
SHINYLIVE_R_VERSION <- as.character(utils::packageVersion("shinylive"))
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -191,13 +188,13 @@ 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
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/")
```
22 changes: 22 additions & 0 deletions local/shiny-apps/issue-029-r/app.R
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 3 additions & 6 deletions man/export.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a84b8b7

Please sign in to comment.