R and Tableau. Installing and connecting to R (local).

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).

  1. Install the Rserve package. This can be done with the install.packages() function.
    > install.packages(“Rserve”)

    Alternatively you can download the R package from this site.

  2. 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).

    2017-01-02_23-52-21

    > library(Rserve)

  3. Run the Rserve function.
    > Rserve()

    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.

    rserve

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).

2017-01-03_19-02-05

You should then test your connection using the ‘Test Connection’ button, if  everything is set up correctly you should receive the following message…

2017-01-03_19-07-05

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.

Ben

Advertisements

One thought on “R and Tableau. Installing and connecting to R (local).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s