管道工 R 包 - post 请求不工作

Plumber R package - post request not working

我尝试使用管道工包提出 post 请求。

library(jsonlite)
#* @post /sum
addTwo <- function(a, b){
  x <- as.numeric(a) + as.numeric(b)
  return(x)
}

然后我写

library("plumber") r <- plumb("C:/.../post.R")

但随后出现错误:

Warning message: In readLines(file) : incomplete final line found on 'C:/.../post.R'

这只是一个警告,表示您的 post.R 文件中没有尾随换行符。您可以忽略它或在文件末尾添加一个空行以使其消失。

实际问题是你从来没有运行 API,只是定义它。

# Load Plumber
library("plumber") 

# define the plumber router in the variable r
r <- plumb("C:/.../post.R")

# Run r on port 8000
r$run(port=8000)