I need to send a json file with multiple values and receive it in R using plumber, ive tried this but it doesnt seem to work,
library("rjson")
#install.packages("rjson")
#* @get /predict
#* @post /predict
function(predict) {
# Load the package required to read JSON files.
library("rjson")
# Give the input file name to the function.
result <- fromJSON(file = "input_v3.json")
print(result)
result <- as.data.frame(result)
write.table(result, file="testing_v3_xyz.csv", sep=",", row.names=FALSE, col.names=TRUE, append = T)
}
The curl command i used is curl -F data=@input_v3.json http://xx.xxx.xxx.xx:8000/predict
I need to send it a an ip address that is Rstudio in Desktop running on aws
plumber
unpacks JSON transparently if you send it in via--data
:Running this API locally I get:
If the top level of the JSON is an array as opposed to an object, you cannot use named parameters to get the data into the function. However, you can use
req$postBody
to access the posted content:For me this works for sample data like this: