刚开始使用plumber API,尝试部署R模型时,我保存了R模型和一个测试数据(OneRecord)。从CMD行运行管道工API,127.0.0.1:8000返回错误"{" Error ":"500 -内部服务器错误“}”,终端显示错误"simpleError in if (opts$show.learner.output) identity else capture.output: argument is is length 0“
我的R代码
#plumb_test.R
library(plumber)
#Simple msg command
#* @apiTitle Plumber Example API
#* Echo back the input
#* @param msg The message to echo
#* @get /echo
function(msg=""){
list(msg = paste0("The message is: '", msg, "'"))
}
#My Model
#* @get /run
function(){
rf_prediction <- predict(readRDS("rf_unwrap.rds"), newdata = as.data.frame(readRDS("Test_data.Rds")))
rf_prediction$data
}管道工运行的R代码
library(plumber)
pr <- plumb("plumb_test.R")
pr$run(port=8000)味精正常工作
http://127.0.0.1:8000/echo?msg=hellohru
returns me
{"msg":["The message is: 'hellohru'"]}但我的模型又回来了
{"error":["500 - Internal server error"]}
in the terminal I am getting
> pr$run(port=8000)
Starting server to listen on port 8000
<simpleError in if (opts$show.learner.output) identity else capture.output: argument is of length zero>我正在从windows cmd行运行,如下所示
C:\R\R-3.5.2\bin>r -f plumb_run.R所有文件都在bin文件夹中(模型、测试数据、铅垂R脚本)
期望预测的输出,不确定错误是什么意思。
发布于 2019-05-17 09:57:48
加载mlr库和plumber,并在函数中使用print,一切都正常
library(plumber)
library(mlr)
#My Model
#* @get /run
function(){
print(predict(readRDS("rf_unwrap.rds"), newdata = as.data.frame(readRDS("Test_data.Rds")))$data)
}https://stackoverflow.com/questions/56177710
复制相似问题