Data Science Toolbox: How to use Julia with Tableau

Julia in Tableau: R allows Tableau to execute Julia code on the fly, enhancing your data analytics experience.
Julia in Tableau: R allows Tableau to execute Julia code on the fly, enhancing your data analytics experience.

Michael, a data scientist, who is working for a German railway and logistics company, recently told me during a FATUG Meetup that he loves Tableau’s R integration and Tableau’s Python integration. As he continued, he raised the question of using functions they have written in Julia. Julia, a high-level dynamic programming language for high-performance numerical analysis, is an integral part of the newly developed data strategy in Michael’s organization.

Tableau, however, does not come with native support for Julia. I didn’t want to keep Michael’s team down and was looking for an alternative way to integrate Julia with Tableau.

This solution is working flawlessly in a production environment for several months. In this tutorial, I’m going to walk you through the installation and connecting Tableau with R and Julia. I will also give you an example of calling a Julia statement from Tableau to calculate the sphere volume.

Step by Step: Integrating Julia in Tableau

1. Install Julia and add PATH variable

You can download Julia from julialang.org. Add Julia’s installation path to the PATH environment variable.

2. Install R, XRJulia, and RServe

You can download base R from r-project.org. Next, invoke R from the terminal to install the XRJulia and the RServe packages:

> install.packages("XRJulia")
> install.packages("Rserve")

XRJulia provides an interface from R to Julia. RServe is a TCP/IP server that allows Tableau to use facilities of R.

3. Load libraries and start RServe

After packages are successfully installed, we load them and run RServe:

> library(XRJulia)
> library(Rserve)
> Rserve()

Make sure to repeat this step every time you restart your R session.

4. Connecting Tableau to RServe

Now let’s open the Help menu in Tableau Desktop and choose Settings and Performance >Manage External Service connection to open the External Service Connection dialog box:

TC17 External Service Connection

Enter a server name using a domain or an IP address and specify a port. Port 6311 is the default port used by Rserve. Take a look at my R tutorial to learn more about Tableau’s R integration.

5. Adding Julia code to a Calculated Field

You can invoke Calculated Field functions called SCRIPT_STR, SCRIPT_REAL, SCRIPT_BOOL, and SCRIPT_INT to embed your Julia code in Tableau, such as this simple snippet that calculates sphere volume:


SCRIPT_INT('
library(XRJulia)
if (!exists("ev")) ev <- RJulia()
y <- juliaEval("
4 / 3 * %s * ' + STR([Factor]) + ' * pi ^ 3
", .arg1)
',
[Radius])

6. Use Calculated Field in Tableau

You can now use your Julia calculation as an alternate Calculated Field in your Tableau worksheet:

Using Julia within calculations in Tableau (click to enlarge)
Using Julia calculations within Tableau (click to enlarge)

Feel free to download the Tableau Packaged Workbook (twbx) here.

Further Reading: Mastering Julia

If you want to go beyond this tutorial and explore more about Julia in the context of data science, I recommend the book Mastering Julia. You can find it here.

Further Reading: Visual Analytics with Tableau

Join the data science conversation and follow me on Twitter and LinkedIn for more tips, tricks, and tutorials on Julia in Tableau and other data analytics topics. If you’re looking to master Tableau, don’t forget to preorder your copy of my upcoming book, Visual Analytics with Tableau. (Amazon). It offers an in-depth exploration of data visualization techniques and best practices.

Also, feel free to comment and share my Tableau Julia Tutorial tweet:

Tableau Conference TC17 Sneak Peek: Integrating Julia for Advanced Analytics

Demo: using Julia within calculations in Tableau (click to enlarge)
Demo: using Julia calculations within Tableau (click to enlarge)

We have already seen some love from Tableau for R and Python, boosting Tableau’s Advanced Analytics capabilities.

So what is the next big thing for our Data Science Rockstars? Julia!

Who is Julia?

JuliaJulia logo is a high-level dynamic programming language introduced in 2012. Designed to address the needs of high-performance numerical analysis its syntax is very similar to MATLAB. If you are used to MATLAB, you will be very quick to get on track with Julia.

Compared to R and Python, Julia is significantly faster (close to C and FORTRAN, see benchmark). Based on Tableau’s R integration, Julia is a fantastic addition to Tableau’s Advanced Analytics stack and to your data science toolbox.

Where can I learn more?

Do you want to learn more about Advanced Analytics and how to leverage Tableau with R, Python, and Julia? Meet me at the 2017 Tableau Conferences in London, Berlin, or Las Vegas and join my Advanced Analytics sessions:

Will there be an online tutorial?

Yes, of course! I published tutorials for R and Python on this blog. And I will also publish a Julia tutorial soon. Feel free to follow me on Twitter @xlth, and leave me your feedback/suggestions in the comment section below.

Further reading: Mastering Julia

A German translation of this post is published on the official Tableau blog: Tableau Conference On Tour Sneak Peek: Julia-Integration für Advanced Analytics

Update 11 Oct 2017: The Julia+Tableau tutorial blog post is now published.