Yesterday I outlined my desire to blog more on the integration between R and Tableau; and where better to start than the initial connection process.
So what do you need to get Tableau and R connected?
Well 1st things first, you need to have R installed on your local machine. In order to do this you should navigate to this site and install an appropriate CRAN mirror (appropriate to your country).
The traditional R user interface is a very basic and most people prefer to install a second tool that provides them with an easier interface to interact with.
My personal recommendation is RStudio and this will be the programme which I will base my demo’s on, however other interfaces will interact in a similar way. If you wish to view other available secondary platforms you could try this site which identifies the 7 best interfaces.
Now in order for Tableau to be able to communicate with R you need to install and initiate an instance of Rserve.
Rserve is a TCP/IP server which enables other software packages to use and pass commands into R. It essentially acts as a traditional server in that it listens to and actions incoming requests.
Fortunately creating a local instance of Rserve can be done in 2 steps once the package is installed (3 steps if not).
- Install the Rserve package. This can be done with the install.packages() function.
Alternatively you can download the R package from this site.
- Open the Rserve library to enable us to access the functions available. You can use either the library() function or navigate to the ‘Packages’ pane and select the Rserve package from the list box selection (what you will notice is this essentially just passes in the library() function automatically into the console and processes it).
- Run the Rserve function.
Now in the case of a local connection (i.e. on your desktop), you will likely run the command without passing any of the available parameters into the function, however there may be cases where you want to make use of the arguments which you can make; an example would be to change the port with which the Rserve listens to requests from, by default this is set to port 6311.
A finite list of the arguments that can be passed into the Rserve() function can be found here.
Be aware you need to leave R Studio open in order to keep your local instance of Rserve running.
Finally we need to test that Tableau is correctly communicating with our Rserve instance.
In order to do this we need to first open Tableau and then navigate to the help drop down on the top toolbar.
Then select ‘Settings and and Performance’, and then select ‘Manage External Service Connection…’.
This will bring up a menu that allows us to configure our connection to Rserve.
In the ‘Server’ menu we should select ‘localhost’ and in the ‘Port’ menu type in 6311 (unless you changed the default port with which the Rserve is listening too).
You should then test your connection using the ‘Test Connection’ button, if everything is set up correctly you should receive the following message…
If you receive an error you should be able to expand the details to identify and diagnose the error.
At present this guide only focuses on creating and connecting to a local instance of Rserve. In the future I plan on developing a second blog that focuses on connecting Tableau Server with an Rserve instance running on an R Server.