问题
I have a directory with a example API function (testAPI.R
):
#* @get /mean
normalMean <- function(samples=10){
library(plumber)
data <- rnorm(samples)
mean(data)
}
The rsconnect::deployAPI()
function wants to point to a directory with a file named plumber.R
that returns a plumb
object. So I have the file plumber.R
in the directory as:
library(plumber)
plumber::plumb("testAPI.R")
And then calling rsconnect::deployAPI()
on the directory...
It deploys with no errors but seems to have not found the handler: screenshot of the swagger page
回答1:
We're still lacking good docs here, sorry. This will currently only work well when deploying to an RStudio Connect server; hopefully that's what you're using.
Internally, RStudio Connect uses the plumber::plumb(dir=___)
function to invoke your API. You can see the docs there
The directory containing the plumber.R file to parse as the plumber router definition. Alternatively, if an entrypoint.R file is found, it will take precedence and be responsible for returning a runnable Plumber router.
So you should either...
- Rename your primary router to
plumber.R
, in which case RStudio Connect would find and invoke that file when it goes to execute your API. Or - Create an
entrypoint.R
file which returns your primary router. This approach allows you to do some extra customization on your router (or plumb a different file). It looks like the code snippet you provided would actually work if you specify it as theentrypoint.R
file instead of theplumber.R
file.
来源:https://stackoverflow.com/questions/47878677/deploying-plumber-api-via-rsconnect-handler-not-found