Reader small image

You're reading from  Tableau Prep Cookbook

Product typeBook
Published inMar 2021
PublisherPackt
ISBN-139781800563766
Edition1st Edition
Tools
Right arrow
Author (1)
Hendrik Kleine
Hendrik Kleine
author image
Hendrik Kleine

Hendrik Kleine is an advanced analytics leader with 15 years of experience in the analytics space, including in data architecture, engineering, and visualization. He specializes in translating vast amounts of data into easy-to-understand visual communications that provide actionable intelligence. He is an avid innovator and a listed author of multiple data-related inventions. Before COVID-19, he was a speaker at the most recent Tableau conference in San Francisco.
Read more about Hendrik Kleine

Right arrow

Chapter 8: Data Science in Tableau Prep Builder

In this chapter, you'll learn how to go beyond the built-in capabilities in Tableau Prep Builder by extending it with R and Python code. R and Python are two of the world's most popular programming languages and can perform numerous data science functions. Tableau Prep allows you to pass your data to an R or Python script at any stage during your flow, with the exception of the input data step. When you insert a script, Tableau Prep will pass the data to R or Python using an API. The script will execute in the R or Python environment and then output the results back to Tableau Prep and your flow continues. The ability to embed scripts allows you to greatly improve the functionality of Tableau Prep and perform advanced functions that are not otherwise possible.

In this chapter, we're going to cover the following main topics:

  • Preparing Tableau Prep to work with R
  • Embedding R code in a Tableau Prep flow
  • ...

Technical requirements

To follow along with the recipes in this chapter, you will need Tableau Prep Builder, an internet connection, and administrative rights to install software.

The recipes in this chapter use sample data files that you can download from the book's GitHub repository: https://github.com/PacktPublishing/Tableau-Prep-Cookbook.

Preparing Tableau Prep to work with R

R is a statistical programming language favored by many data scientists. It is available free of charge and benefits from a vast online community for ideation and support. To find out more about R, visit https://www.r-project.org/about.html. R by itself does not support interaction with other applications such as Tableau Prep. In order to extend R with that functionality, we need to install Rserve in addition to R itself.

Important note

The R programming language and the R and RStudio application interfaces are not part of Tableau Prep; they are separate technologies. An in-depth look at R is beyond the scope of this book. However, every system is slightly different, and you may run into unexpected challenges. For help, please refer to the R website: https://cran.r-project.org.

In this recipe, we will provide general guidance for configuring your system successfully.

Getting ready

To follow along with this recipe, download the Sample...

Embedding R code in a Tableau Prep flow

In the previous recipe, you learned how to configure your machine with R. You also set up a connection from Tableau Prep to R, using the Rserve package. In this recipe, we'll leverage that foundational setup to run an R script using Tableau Prep. We'll learn how to embed a script in our flow and understand how R sends the data back to our Tableau Prep data flow. The examples used are simple but form a solid foundation. Once you have mastered the basics, you'll be able to implement more advanced scripts, such as the script in the recipe titled Forecasting time series using R.

Getting ready

To follow along with this recipe, download the Sample Files 8.2 folder from this book's GitHub repository.

Important note

R is a programming language of its own, not covered by this book. We'll look at R code in this recipe at a very high level only, so you will gain sufficient knowledge to integrate R with Tableau Prep...

Forecasting time series using R

In the previous two recipes, Preparing Tableau Prep to work with R and Embedding R code in a Tableau Prep flow, you learned how to set up R, RStudio, and Rserve, as well as integrating an R script into Tableau Prep. The example script used was relatively basic and required no additional configuration. However, R is an extensible programming language, and many functions are bundled in what are called packages. In this recipe, we'll look at a more advanced script that has dependencies on such packages. You'll learn how to prepare R for these complex scripts that require additional preparation.

Getting ready

To follow along with this recipe, download the Sample Files 8.3 folder from this book's GitHub repository.

Important note

The R scripts in this book serve to illustrate the process of integrating R and Tableau Prep. Each dataset must be carefully analyzed prior to applying advanced functionality such as forecasting. The script...

Preparing Tableau Prep to work with Python

Python is a general-purpose programming language ranking highly as one of the most popular languages right now. It is available free of charge and, similar to R, benefits from a community for ideation and support. To find out more about Python, visit https://www.python.org/. In order to allow Tableau Prep to communicate with Python, you need to prepare your machine with a Tableau Python server known as TabPy.

Important note

The Python programming language and the TabPy package are not part of Tableau Prep. Python is a separate technology and an in-depth look at Python is beyond the scope of this book. Every system is slightly different, and you may run into unexpected challenges. For help, please refer to the Python website at https://www.python.org/.

In this recipe, we will provide general guidance for configuring your system successfully.

Getting ready

If you are a Windows user, you must ensure you have Microsoft C++ Build...

Embedding Python code in a Tableau Prep flow

In the previous recipe, we prepared our machine to work with Python, using the Tableau Python server. In this recipe, we'll create a Tableau Prep flow and embed a Python script in it. This process is largely the same as we've practiced in the recipes for R. Using this script, we'll evaluate a dataset and flag anomalies, that is, outliers.

Getting ready

To follow along with this recipe, download the Sample Files 8.5 folder from this book's GitHub repository.

Important note

The Python scripts in this book serve to illustrate the process of integrating Python and Tableau Prep. Each dataset must be carefully analyzed prior to applying advanced functionality such as anomaly detection. The script referenced in this recipe is purely for illustration purposes and is not intended for real-world use.

How to do it…

Start by opening up Tableau Prep and connect to the sales amount by date.csv file from the...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Tableau Prep Cookbook
Published in: Mar 2021Publisher: PacktISBN-13: 9781800563766
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Hendrik Kleine

Hendrik Kleine is an advanced analytics leader with 15 years of experience in the analytics space, including in data architecture, engineering, and visualization. He specializes in translating vast amounts of data into easy-to-understand visual communications that provide actionable intelligence. He is an avid innovator and a listed author of multiple data-related inventions. Before COVID-19, he was a speaker at the most recent Tableau conference in San Francisco.
Read more about Hendrik Kleine