Deploying plumber API via rsconnect (Handler not found)

梦想与她 提交于 2019-12-13 03:49:41

问题


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...

  1. 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
  2. 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 the entrypoint.R file instead of the plumber.R file.


来源:https://stackoverflow.com/questions/47878677/deploying-plumber-api-via-rsconnect-handler-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!