Model deployment and plumber
This resource showcases how to expose a machine learning model built in R via a Plumber API. A model is first trained and saved as an
.rds file. The Plumber file loads this saved model from disk, interprets data submitted via POST request, and returns a JSON object containing predictions based on the input data. A simple Shiny app is provided to interact with the API. Click here for source code.
Train a simple model that predicts MPG.
cars_model <- lm(mpg ~ cyl + hp, data = mtcars) saveRDS(cars_model, here::here("R", "model-api", "cars-model.rds"))
Build an API that predicts MPG based on user inputs and the trained model.
Use a Shiny app to predicts MPG based from the API.