Skip to content

Commit

Permalink
Merge branch 'master' into blairj09-path-rewrite
Browse files Browse the repository at this point in the history
* master:
  Setting `plumber.docs.callback` to `NULL` will also set legacy `plumber.swagger.url` (rstudio#766)
  Update Hosting vignette to swap RStudio Connect and Digital Ocean (rstudio#774)
  • Loading branch information
schloerke committed Feb 26, 2021
2 parents 589a429 + 423696f commit c4637ef
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ plumber 1.0.0.9999 Development version

* Changed `future::plan()` from `multiprocess` to `multisession` in example API `14-future` as "Strategy 'multiprocess' is deprecated in future (>= 1.20.0)". (#747)

* Setting options `plumber.docs.callback` to `NULL` will also set deprecated but supported option `plumber.swagger.url`. (#766)

plumber 1.0.0
--------------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions R/options_plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ options_plumber <- function(
) {
ellipsis::check_dots_empty()

# Make sure all fallback options are disabled
if (!missing(docs.callback) && is.null(docs.callback)) {
options("plumber.swagger.url" = NULL)
}

options(
plumber.port = port,
plumber.docs = docs,
Expand Down
2 changes: 1 addition & 1 deletion R/plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Plumber <- R6Class(
self$set404Handler(default404Handler)
self$setDocs(TRUE)
private$docs_info$has_not_been_set <- TRUE # set to know if `$setDocs()` has been called before `$run()`
self$setDocsCallback(getOption('plumber.docs.callback', getOption('plumber.swagger.url', NULL)))
self$setDocsCallback(getOption('plumber.docs.callback', getOption('plumber.swagger.url')))
self$setDebug(interactive())
self$setApiSpec(NULL)

Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-options.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,12 @@ test_that("Legacy swagger redirect can be disabled", {
expect_equal(length(redirects), 0)
})
})

test_that("docs.callback sync plumber.swagger.url", {
with_options(list(), {
options("plumber.swagger.url" = function(api_url) {cat(api_url)})
opt <- options_plumber(docs.callback = NULL)
expect_null(getOption("plumber.swagger.url"))
expect_null(opt$plumber.docs.callback)
})
})
14 changes: 6 additions & 8 deletions vignettes/hosting.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,24 @@ Once you have developed your Plumber API, the next step is to find a way to host
1. If your Plumber process crashes (for instance, due to your server running out of memory), the method of running Plumber will not automatically restart the crashed service for you. This means that your API will be offline until you manually login and restart it. Likewise if your development machine gets rebooted, your API will not automatically be started when the machine comes back online.
1. This technique relies on having your clients specify a port number manually. Non-technical users may be tripped up by this; some of the other techniques do not require clients specifying the port for an API.
1. This approach will eternally run one R process for your API. Some of the other approaches will allow you to load-balance traffic between multiple R processes to handle more requests. [RStudio Connect](#rstudio-connect) will even dynamically scale the number of running processes for you so that your API isn't consuming more system resources than is necessary.
1. Plumber uses the `interactive()` function as a heuristic for whether it should behave in a more convenient mode or in a more robust, secure mode. This function is used as the default for some parameters on `run()` which could pose a security hazard if enabled on a public server.
1. Most importantly, serving public requests from your development environment can be a security hazard. Ideally, you should separate your development instances from the servers that are accessible by others.


For these reasons and more, you should consider setting up a separate server on which you can host your Plumber APIs. There are a variety of options that you can consider.

## DigitalOcean {#digitalocean}
## RStudio Connect {#rstudio-connect}

[DigitalOcean](https://m.do.co/c/add0b50f54c4) is an easy-to-use Cloud Computing provider. They offer a simple way to spin up a Linux virtual machine and access it remotely. You can choose what size machine you want to run -- with options ranging from small machines with 512MB of RAM for a few dollars a month up to large machines with dozens of GB of RAM -- and only pay for it while it's online.
[RStudio Connect](https://rstudio.com/products/connect/) is an enterprise publishing platform from RStudio. It supports push-button publishing from the RStudio IDE of a variety of R content types including Plumber APIs. Unlike all the other options listed here, RStudio Connect automatically manages the dependent packages and files your API has and recreates an environment closely mimicking your local development environment on the server.

To deploy your Plumber API to DigitalOcean, please check out the `plumber` companion package [`plumberDeploy`](https://github.com/meztez/plumberDeploy).
RStudio Connect automatically manages the number of R processes necessary to handle the current load and balances incoming traffic across all available processes. It can also shut down idle processes when they're not in use. This allows you to run the appropriate number of R processes to scale your capacity to accommodate the current load.


## RStudio Connect {#rstudio-connect}
## DigitalOcean {#digitalocean}

[RStudio Connect](https://rstudio.com/products/connect/) is an enterprise publishing platform from RStudio. It supports push-button publishing from the RStudio IDE of a variety of R content types including Plumber APIs. Unlike all the other options listed here, RStudio Connect automatically manages the dependent packages and files your API has and recreates an environment closely mimicking your local development environment on the server.
[DigitalOcean](https://m.do.co/c/add0b50f54c4) is an easy-to-use Cloud Computing provider. They offer a simple way to spin up a Linux virtual machine and access it remotely. You can choose what size machine you want to run -- with options ranging from small machines with 512MB of RAM for a few dollars a month up to large machines with dozens of GB of RAM -- and only pay for it while it's online.

RStudio Connect automatically manages the number of R processes necessary to handle the current load and balances incoming traffic across all available processes. It can also shut down idle processes when they're not in use. This allows you to run the appropriate number of R processes to scale your capacity to accommodate the current load.
To deploy your Plumber API to DigitalOcean, please check out the `plumber` companion package [`plumberDeploy`](https://github.com/meztez/plumberDeploy).

> Conflict of interest: the primary authors of `plumber` work for RStudio.

## Docker (Basic) {#docker}

Expand Down

0 comments on commit c4637ef

Please sign in to comment.