How to publish/produce datapoints to an API from R?

Viewed 16

I have these datapoints from a model I developed and I would like to publish an API using R. I've explored the plumber library within R from this YouTube video. However, the tutorials I have encountered tend to share very minimal and uncomplicated datasets (not that mine is anything crazy). I just haven't been able to fully understand the syntax of plumber or how the functions work.

Here is an example/shortend verison of my data and what I would like to produce as an API:

ID BRANCH_ZIP_1 STR_ZIP_1 CONFIGURATION PREDICTION
60804002 3 3 33 7

Additionally, I have multiple rows of this data so would be great if there is a functional solution rather than a static solution with this one example I shared.

I understand I will need to host it somewhere, can swagger or digital ocean take care of that?

I converted my data frame to JSON as follows

f <- toJSON(predictions)

f returns:

[{"MVNDR_NBR":60804002,"MVNDR_NM":"S/O WEYERHAEUSER NR CO.","BRANCH_ZIP_1":3,"STR_ZIP_1":3,"CONFIGURATION":"33","BRANCH_REGION":"SOUTHEAST","STR_REGION":"0024","PREDICTED_LEAD_TIME":19,"WEEK_TO_APPLY":"202233"},

{"MVNDR_NBR":60804002,"MVNDR_NM":"S/O WEYERHAEUSER NR CO.","BRANCH_ZIP_1":3,"STR_ZIP_1":3,"CONFIGURATION":"33","BRANCH_REGION":"SOUTHEAST","STR_REGION":"0047","PREDICTED_LEAD_TIME":16,"WEEK_TO_APPLY":"202233"}] 

How do I get this JSON blob above to return an API that provides this data. I am not understanding how to write this code in plumber with the functions required.

0 Answers
Related