How to use API created from PLUMBER for bulk data prediction


I have prepared the predictive model and I have also created an API using Plumber package for the same model. Now I want to use this API for doing predictions on the raw data having 100 records. I am not getting that how to import the raw data file and leverage the API to make predictions ? How can we use the same API for making the predictions on the other PC as well ?

You're much more likely to attract answers with a reproducible example, called a reprex than a screenshot.


I have created an API for the model using the Plumber package. How can I use this API to do the prediction on the bulk raw data which is either in CSV or excel file?


Hi @karansehgal1988,
This GitHub repository provides a pattern for doing what you've requested. Specifically, this section of code shows how to take an incoming request and calculate bulk predictions on data provided in the request.

The main idea is that the data you want to predict with will need to be included in the body of a POST request made to the API. The way you assemble this request will depend on what tool you are using to interact with the API. Once the API receives the request, the data can be parsed into an R object (in the example referenced this means parsing the JSON data into a data.frame) that is then used in connection with a model to generate predicted values.

Hope that helps provide some clarity!


Hi @Blair09M ,

Thanks for your reply.

How to post the data to the API created using the plumber package? How to make the API run somewhere at the backend of the RStudio? because if I run this API on the Rstudio then Rstudio becomes busy and I am unable to do the rest of the tasks on the same. Can you please share the link or can you please comment on the same as it's making me confused.

Thanks in advance.

There are a variety of methods for hosting Plumber APIs externally. These can be found in the hosting section of the Plumber documentation.

One of the simplest methods for deploying Plumber APIs is RStudio Connect. This is a commercial solution that provides easy, push-button deployment of Plumber APIs along with additional security and scalability features.

I'm not sure if I understand your question about posting the data to the API. Are you looking for how to create an API request containing the data? This depends on the tool you're using to make the request. The following example shows how you could use R to make a request to a Plumber API and include data for a prediction:

httr::POST(url = "<url-to-api>", body = data, encode = "json")

Where data is the data you want to send to the API for prediction.

If you're looking for an interactive tool for sending requests to APIs, you may want to take a look at Postman, which provides a GUI for working with APIs.


Hi @Blair09M,

Thanks for your response.

Firstly if I want to deploy the model in the local machine then how to do the same so that we can access the API from the remote locations also? Secondly, I want to run the model at the backend of the RStudio in the local machine itself, how to do the same? Thirdly Is there any free platform for deploying the R models Commercially as RStudio Connect seems to be paid service?


There are details on other ways of deploying Plumber APIs in the hosting section of the Plumber documentation. Many of these options (Docker, pm2, systemd) can be used locally, depending on your operating system.
However, it's worth noting that creating a responsive API is often dependent on having a server dedicated to running the API, rather than relying on a local machine that likely won't maintain a persistent API process. The section on Digital Ocean in the Plumber documentation provides a guide for hosting Plumber APIs on Digital Ocean, which allows you to rent servers for a small fee. This approach allows you to setup a persistent server that supports the API.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.