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} }