rstudio / plumber

Turn your R code into a web API.
https://www.rplumber.io
Other
1.38k stars 256 forks source link

Documentation about deploying programmatically built plumber api on RStudio Connect #868

Open ColinFay opened 2 years ago

ColinFay commented 2 years ago

Given the following plumber.R:

library(plumber)

#* @apiTitle Plumber Example API

pr() %>%
  pr_get("/", function(){
    "<html><h1>Programmatic Plumber!</h1></html>"
  }, serializer = plumber::serializer_html())

If I publish to RStudio Connect the file as is, the API is empty. I wasn't able to find documentation about deploying this structure on Connect.

Any chance this could be added to the pkgdown website?

Thanks :)

schloerke commented 2 years ago

The plumber.R file needs to be plumbI()-able. So it must use annotations vs returning a working pr object.

Untested plumber.R code which uses a @plumber decorator to update the "currently being plumb()ed" router:

library(plumber)

#* @apiTitle Plumber Example API

#* @plumber
function(pr) {
  pr %>%
    pr_get("/", function(){
      "<html><h1>Programmatic Plumber!</h1></html>"
    }, serializer = plumber::serializer_html())
}
meztez commented 7 months ago

@ColinFay You can also name your file entrypoint.R

entrypoint.R

library(plumber)
pr() |> 
  pr_get("/", function(){
    "<html><h1>Programmatic Plumber!</h1></html>"
  }, serializer = plumber::serializer_html()) |>
  pr_set_docs("swagger")

Then deploy to connect

rsconnect::deployApp(appFiles = "entrypoint.R", appMode = "api")