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 and 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.
1. Install Julia and add PATH 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:
3. Load libraries and start RServe
After packages are successfully installed, we load them and run 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:
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|if (!exists("ev")) ev <- RJulia()|
|y <- juliaEval("|
|4 / 3 * %s * ' + STR([Factor]) + ' * pi ^ 3|
6. Use Calculated Field in Tableau
You can now use your Julia calculation as an alternate Calculated Field in your Tableau worksheet:
Feel free to download the Tableau Packaged Workbook (twbx) here.
Further reading: Mastering Julia
— Alexander Loth (@xlth) October 11, 2017