【问题标题】:How to Deploy model using plumber API from CMD line R?如何使用 CMD line R 中的管道工 API 部署模型?
【发布时间】:2019-05-16 23:16:04
【问题描述】:

刚开始使用管道工 API,尝试部署 R 模型,我保存了 R 模型和测试数据 (OneRecord)。从 CMD 行运行管道工 API,127.0.0.1:8000 返回错误 "{"error":["500 - Internal server error"]}" 并且终端显示错误“simpleError in if (opts$show.learner.output) identity else capture.output: argument is of length zero”

我的 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 文件夹中(模型、测试数据、plumb R 脚本)

期待预测的输出,不知道错误是什么意思。

【问题讨论】:

标签: mlr plumber


【解决方案1】:

与管道工一起加载 mlr 库并在函数中使用 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)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多