Integrating Tableau and R: Failing silently is not an option

Back in May, I wrote an article with intermediate tips and tricks on how to integrate Tableau and R (make sure to check it out if you haven’t so far). However, I decided to leave error handling out. Instead, an understanding of what went wrong with your R code inside of Tableau is worthy of an article on its own. 

 

Imagine the following situation:

You have a small database full of clients and the marketing team asks you to predict their gender. You, of course, understand that gender is a social construct and not everybody adheres to a binary gender spectrum. But regardless of that, you do it. You find a cool package in R called genderizeR that calls the genderize.io API and sends back a prediction. 

The first time you try it in R, it works like a charm! 99% of the names were properly classified. You adapt the code to integrate it into your Tableau dashboard and it also works without problems. Then, you do one small change to the code. Now the API only classified the first half of the names and returned NULL for the second half. You try to modify the code again and this time all of the predictions are gone! 

At this point, something is wrong but you don’t know what, and Tableau is not telling you either. It turns out that there is a free API plan that limits you to 1000 queries a day. This would be evident if you would run this code from your IDE or R console. If you do so, you will get this message:

Client error: (429) Too Many Requests (RFC 6585) Request limit too low to process requestThe API queries stopped at 90 term. If you have reached the end of your API limit, you can start the function again from that term and continue finding given names next time with efficient use of the API. Remember to add the results to already found names and not to overwrite them.

This is just one example and I used a very niche use case (i.e. predicting the gender) to illustrate it. But the problem is that when you run R code from Tableau, it will often fail silently. Occasionally, you will see an error prompt that might be helpful to troubleshoot your script. However, you won’t ever see the error messages that the developers of the package left for you to see. 

There is actually a neat solution for this problem, which is working side by side with the Rterm. Every time you ask Tableau to run an R script, it will send a request to the Rserve you are currently running. If you are running this R script from your own computer (i.e. localhost:6311), all of the requests and output will be visible from the Rterm. Without any extra effort, your script will obtain a lot more information about everything that is happening in the background. 

Where to find the Rterm?

In case you are wondering where to find the Rterm, it is in the place where you installed R inside of the bin/i386 folder. In my case “C:\Program Files\R\R-3.6.0\bin\i386\Rterm.exe”. However, this might look a bit different for you depending on where you installed R and which version you installed. 

Thanks for reading this far, I hope this tip was helpful. If you have any questions, thoughts, or remarks about the R connection, feel free to contact me or any of our colleagues from the Biztory Data Science Practice. We are always happy to discuss your use cases.

Author
Timothy Vermeiren

Timothy Vermeiren

Analytics Domain Lead at Biztory, and DataDev Ambassador. Tableau Iron Viz 2018 Global Champion, Tableau Ambassador 2020-2021, Tableau Certified Consultant & Architect. He runs in his spare time & plays various musical instruments.

Read more articles of this author
Let's discuss your data challenges

Join our community of data enthusiasts

Get industry insights, expert tips and Biztory news sent straight to your inbox with our monthly newsletter.