R/plumberで引数を持つAPI
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__/
Author And Source
この問題について(R/plumberで引数を持つAPI), 我々は、より多くの情報をここで見つけました https://qiita.com/yono2844/items/c47fe7d64b3be1dbbadb著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .