Hi,
I'm writing a plumber API to keep large datasets out of a Shiny app but would like the parameters to accept a vector of values in a filter. I have tried to give a reproducible example below
library(plumber)
#* @apiTitle Filter mtcars
#* Return the mtcars filtered
#* @param f1 Filter to select single filter
#* @get /mtcars/filter
function(f1) {
mtcars[mtcars$cyl %in% f1,]
}
If I want all the rows where cyl == 4 using http://127.0.0.1:8160/mtcars/filter?f1=4 the API correctly returns 11 rows
When I want all the data from the API using the filter I have to construct the call as follows http://127.0.0.1:8160/mtcars/filter?f1=4&f1=6&f1=8
I was wondering what is the best way to construct the API call from Shiny using the input$filter_cyl
I would like to generate the following dynamically
For all 3 selected:
api_call = glue::glue("?f1={f1[[1]]}&f1={f1[[2]]}&f1={f1[[3]]}"))
For only 2 values selected:
api_call = glue::glue("?f1={f1[[1]]}&f1={f1[[2]]}"))
For only 1 value selected:
api_call = glue::glue("?f1={f1[[1]]}"))
I can do the if but was wondering if there is a better way.
Thank you