Skip to content

Commit

Permalink
feat: Use httpuv::runStaticServer(dir) instead of {plumber} (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke authored Nov 30, 2023
1 parent 11aeb30 commit 5390387
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 22 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre"),
Expand All @@ -27,7 +27,7 @@ Imports:
rlang,
tools
Suggests:
plumber,
httpuv (>= 1.6.12),
spelling,
testthat (>= 3.0.0)
Config/Needs/website: tidyverse/tidytemplate
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
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
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 5390387

Please sign in to comment.