Alteryx Designer Knowledge Base

Definitive answers from Designer experts.

How To: Work With Custom R and Python Models in Alteryx Designer

Alteryx Community Team
Alteryx Community Team

Alteryx Designer comes with tools (based on both R and Python) to create and use predictive models without needing to write any code. But what if you've got custom models written in R or Python outside of Designer that you want to use in Designer, or vice versa?


For Python, use pickle or joblib to move the model in and out of Python. Here's an example that fits a decision tree model to the iris dataset and dumps the model to disk as a joblib file:


from ayx import Package

from ayx import Alteryx
from sklearn import tree
from joblib import dump

train ="#1")
clf = tree.DecisionTreeClassifier()
y_train = train.pop('Species').values
clf =, y_train)
dump(clf, 'C:/Users/nryan/Desktop/treeModel.joblib')


Use RDS files in R:



train <- read.Alteryx("#1", mode="data.frame")
treeFit <- rpart(Species ~ ., data=train, method = 'class')
saveRDS(treeFit, "C:/Users/nryan/Desktop/treeModel.rds")


Bringing the joblib file back into Alteryx is straightforward. Here we bring the decision tree model back into the Python tool in Designer to make predictions on new data:


from ayx import Package

from ayx import Alteryx
import pandas as pd
from joblib import load

test ="#1")
clf = load('C:/Users/nryan/Desktop/treeModel.joblib')
prediction = clf.predict(test)
Alteryx.write(pd.DataFrame({'Py_Prediction':prediction}), 1)


And the R tool equivalent:


treeModel <- readRDS("C:/Users/nryan/Desktop/treeModel.rds")
test <- read.Alteryx("#1", mode="data.frame")
R_Prediction <- predict(treeModel, newdata=test, type = 'class')
write.Alteryx(, 1)


Fit the modelFit the model


Make predictionsMake predictions

See attached example workflows. To run these workflows you will need to edit the file paths to reflect a location on your machine. For help installing the joblib package, please see the article How To: Use Alteryx.installPackages() in Python tool

5 - Atom

One of your examples here is just what I'm trying to do but I get an error when trying to load the package 'rpart' in the R tool.   I can see it's in the library but get these error messages:


R (59) Error: package or namespace load failed for 'AlteryxPredictive' in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):


R (59) there is no package called 'rpart'


The R command that causes this is: library(rpart)


Can you help?  My company wants me to get this predictor on-line and this is the last step I need to do it!


Bill Bentley



Alteryx Community Team
Alteryx Community Team

@billb007 Can you share your workflow?

5 - Atom
I'd love to send the workflow to you but our company has extreme security and I have to send it via their secure file process. That process will not recognize the email address you have as valid do you have a simpler, more standard email I can send this to?

Bill Bentley

This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, notify the sender immediately by return email and delete the message and any attachments from your system.
Alteryx Community Team
Alteryx Community Team

@billb007 I'll private message you.