Setup dependencies

Firstly, install/update all the necessary dependencies. It is crucial that you use github development version of plumber in order to deploy the API to the cloud. For local use only the CRAN version is sufficient.

# install plumber from github
devtools::install_github("trestletech/plumber")
# update main dependencies
install.packages("ingredients")
install.packages("iBreakDown")
install.packages("readr")
install.packages("whisker")
# packages for explainer objects
install.packages("DALEX")
# install packages for the used model
install.packages("randomForest")
# install useful packages for DigitalOcean connection
install.packages("analogsea")

Deploy the explainer locally

library("xai2cloud")
library("DALEX")
library("randomForest")

# Load data
titanic <- na.omit(DALEX::titanic)
# Create a random forest model
model_titanic_rf <- randomForest(survived == "yes" ~ gender + age + class + embarked +
                                   fare + sibsp + parch,  data = titanic)
# Create an DALEX explainer
explain_titanic_rf <- DALEX::explain(model_titanic_rf, 
                      data = titanic[,-9],
                      y = titanic$survived == "yes", 
                      label = "Random Forest v7",
                      colorize = FALSE)
# Deploy the explainer
deploy_explainer(explain_titanic_rf, model_package = "randomForest", title="Vignette test", port=8080)

Deploy the explainer to DigitalOcean

In order to deploy the explainer to the cloud using DigitalOcean’s droplets you need an DigitalOcean’s account and a droplet with R version >=3.5 and corresponding packages. In order to setup the droplet properly visit the README section on github.

Assuming the guide has been completed, let’s deploy the explainer.

# First get your droplet's id using analogsea package
library(analogsea)
my_droplets <-droplets()
# Choose the correct droplets name - 'xai2cloudExamples' in this case
specific_droplet <-my_droplets$xai2cloudExamples
droplet_id <-specific_droplet$id
# We will use the explainer from the previous, local example
# Deploy it to your new droplet
deploy_explainer(explain_titanic_rf, model_package = "randomForest", title = "Vignette test", droplet = droplet_id, port=8080)
# Your explainer is ready at: http://your_droplets_ip/explain_titanic_rf/__swagger__/
# You can deploy multiple explainers to the same droplet, just use different names and ports
# If you wish to delete the explainer from your droplet, use:
plumber::do_remove_api(droplet = 185232162, path = "explain_titanic_rf", delete = TRUE)

The droplet is now available at the droplet’s address and will be there untill it’s removal using the above mentioned plumber funtion or via DigitalOcean’s website.