R/plumber에 인수가 있는 API

11400 단어 Rplumber
UCI Water Treatment Plant Data Set를 사용하여 인수가있는 API를 만들려고했습니다.

인수가 없는 API



wtapi.R
library(plumber)
library(stringr)
library(lubridate)

x <- read.csv(file = "water-treatment.data", header = FALSE, na.strings = "?")
x$V1 <- dmy(str_sub(x$V1, start = 3))

#* @get /wt
function() {
  return(x)
}
> pr("wtapi.R") %>% pr_run(port=8000)
Running plumber API at http://127.0.0.1:8000
Argument of class Date cannot be used to set default value in OpenAPI Specifications.
Argument of class Date cannot be used to set default value in OpenAPI Specifications.
Running swagger Docs at http://127.0.0.1:8000/__docs__/



인수가 있는 API



wtapi.R
library(plumber)
library(stringr)
library(lubridate)
library(dplyr)

x <- read.csv(file = "water-treatment.data", header = FALSE, na.strings = "?")
x$V1 <- dmy(str_sub(x$V1, start = 3))

#* @get /wt
function(start=x$V1[1], end=x$V1[dim(x)[1]]) {
  x %>% filter(V1 >= start & V1 <= end) %>% return()
}
> pr("wtapi.R") %>% pr_run(port=8000)
Running plumber API at http://127.0.0.1:8000
Argument of class Date cannot be used to set default value in OpenAPI Specifications.
Argument of class Date cannot be used to set default value in OpenAPI Specifications.
Running swagger Docs at http://127.0.0.1:8000/__docs__/

좋은 웹페이지 즐겨찾기