通过rsconnect部署管道工API(未找到处理程序) [英] Deploying plumber API via rsconnect (Handler not found)
问题描述
我有一个带有示例API函数(testAPI.R
)的目录:
I have a directory with a example API function (testAPI.R
):
#* @get /mean
normalMean <- function(samples=10){
library(plumber)
data <- rnorm(samples)
mean(data)
}
rsconnect::deployAPI()
函数希望指向包含名为plumber.R
的文件的目录,该文件返回plumb
对象.所以我在目录中的文件plumber.R
为:
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")
然后在目录上调用rsconnect::deployAPI()
...
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
推荐答案
抱歉,我们这里仍然缺少好的文档.当前,这仅在部署到RStudio Connect服务器时才能很好地运行.希望这就是您所使用的.
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.
内部,RStudio Connect使用plumber::plumb(dir=___)
函数来调用您的API.您可以在此处看到文档
Internally, RStudio Connect uses the plumber::plumb(dir=___)
function to invoke your API. You can see the docs there
包含plumber.R文件的目录,该文件要解析为plumber路由器定义.另外,如果找到entrypoint.R文件,它将具有优先权并负责返回可运行的Plumber路由器.
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.
所以您应该...
- 将您的主路由器重命名为
plumber.R
,在这种情况下,RStudio Connect将在执行API时找到并调用该文件.或者 - 创建一个
entrypoint.R
文件,该文件将返回您的主路由器.这种方法允许您在路由器上进行一些额外的自定义(或获取其他文件).如果您将其指定为entrypoint.R
文件而不是plumber.R
文件,则看起来您提供的代码片段实际上可以正常工作.
- 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.
这篇关于通过rsconnect部署管道工API(未找到处理程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!