Moving from data visualization into deeper, more advanced analytics? This book will intensify data skills for a data-savvy user who wants to move into analytics and data science in order to make a difference to their businesses, by harnessing the analytical power of R and the stunning visualization capabilities of Tableau.
Together, Tableau and R offer accessible analytics by allowing a combination of easy-to-use data visualization along with industry-standard, robust statistical computation. Readers will come across a wide range of machine learning algorithms and learn how descriptive, prescriptive, and predictive visually appealing analytical solutions can be designed solutions with R and Tableau.
Let's get ready to start our transition from being a data-savvy user to a data analyst using sound statistical tools to perform advanced analytics. To do this, we need to get the tools ready. In this topic, we will commence our journey of conducting Tableau analytics with the industry-standard, statistical prowess of R. As the first step on our journey, we will cover the installation of R, including key points about ensuring the right bitness before we start. In order to create R scripts easily, we will install RStudio for ease of use.
We need to get R and Tableau to communicate, and to achieve this communication, we will install and configure Rserve.
The first step is to download your required version of R from the CRAN website [http://www.rproject.org/].
Go to the official R website, which you can find at https://www.r-project.org/.
The download link can be found on the left-hand side of the page.
The next option is for you to choose the location of the server that holds R. The best option is to choose the mirror that is geographically closest to you. For example, if you are based in the UK, then you might choose the mirror that is located in Bristol.
Once you click on the link, there is a section at the top of the page called Download and Install R. There is a different link for each operating system. To download the Windows-specific version of R, there is a link that specifies Download R for Windows. When you click on it, the download links will appear on the next page to download R.
On the next page, there are a number of options, but it is easier to select the option that specifies install R for the first time.
Finally, there is an option at the top of the page that allows you to download the latest R installation package. The install package is wrapped up in an EXE file, and both 32 bit and 64 bit options are wrapped up in the same file.
Now that R is downloaded, the next step is to install R. The instructions are given here:
Double-click on the R executable file, and select the language. In this example, we will use English. Choose your preferred language, and click OK to proceed:
The Welcome page will appear, and you should click Next to continue:
The next step is to specify the destination location for R's files. In this example, the default is selected. Once the destination has been selected, click Next to proceed:
In the next screenshot, the 64-bit User Installation option has been selected:
Next, it's possible to configure some of R's options, such as the creation of a desktop icon. Here, let's choose the default options and click Next:
Finally, R is installed, and you should receive a final window. Click Finish:
help.start()at the R-Console prompt and press Enter. If you can see the help server page then you have successfully installed and configured your R package.
The R interface is not particularly intuitive for beginners. For this reason, RStudio IDE, the desktop version, is an excellent option for interacting with R. The download and installation sequence is provided.
There are two versions; the RStudio Desktop version, and the paid RStudio Server version. In this book, we will focus on the RStudio Desktop IDE option, which is open source.
To download RStudio, you can retrieve it from https://www.rstudio.com/products/rstudio-desktop/.
The next option allows the user to configure the installation location for RStudio. Here, the default option has been retained. If you do change the location, you can click Browse to select your preferred installation folder. Once you've selected your folder, click Next to continue to the next step.
RStudio installs in the next step:
Once completed, launch RStudio IDE. You can find it by navigating to Start | All Programs | RStudio | RStudio.exe. Alternatively, you can type RStudio into the Cortana search box. If you specified a custom installation directory, then you can find RStudio as an EXE file. The default installation directory for RStudio IDE is
help.start()at the RStudio prompt and press Enter. If you can see the help files on the screen then you have successfully installed and configured RStudio IDE to run with R.
Now that we have installed R and RStudio, we can download and install the scripts for this book. This book's scripts and code can be found on GitHub. If the reader hasn't got a free GitHub account, then it's recommended that Git and GitHub are set up. It's good practice for storing your own R scripts at a later date. If required, the reader is referred to the GitHub site for more details. GitHub itself can be found at github.com. Training material can be found at https://training.github.com/kit/.
After setting up Git and GitHub, you can download our data and scripts by taking a copy of this book's GitHub repository. Simply put, a fork is a copy of a repository, and it means that you can freely experiment with changes without affecting the original project. Please refer to the GitHub training material for more information on how to fork a repository, download data and scripts, and how to keep your local copy in sync with changes to the repository.
At the top right-hand corner of the page, click Fork. This means you have forked the repository. The next step is to download the files to your local computer. To do this, you can run the following line of code in your Git Bash:
Open the script in RStudio's script editor.
Go to the Code menu item.
Choose Source from the menu.
Navigate to the
Press Ctrl + A to select the whole script.
In the script window, click Run.
You should see the results in the output window.
If you upload a workbook that contains R functionality to the Tableau server, then the Tableau server must have a connection to an Rserve server. See R Connection, in the Tableau Desktop help, for details.
In this section, we will install, run, and configure Rserve.
Open RStudio and go to the Install Packages tab on the interface.
In the Packages textbox, type
Rserveand click OK.
Rserve will install, and you will see the output messages in the RStudio Console. When it is finished, you will see the chevron again.
Now, open Control Panel on the server, and search for environment variable in the search box.
Click on the Edit the System Environment Variables option.
Add a new variable to the PATH variable path. Add the directory containing
R.dllto your path environment variable. For example,
You should see the new path in the Edit Environment Variable window. You can see a sample image here:
In RStudio, let's call Rserve by running the following command in the RStudio Console:
On the Help menu in Tableau Desktop, choose Settings and Performance | Manage R Connection to open the Rserve connection dialog box.
Enter or select a server name using a domain name or an IP address.
Specify a port (Port 6311) is the default port for Rserve servers.
If the server requires credentials, specify a username and password.
Click Test Connection.
In this chapter, we started on our journey of conducting Tableau analytics with the industry-standard, statistical prowess of R. In this chapter, we covered the installation of R, including a key point about ensuring the right bitness before we start. We also installed RStudio and ran a script, as a way of engaging with R. Finally, we installed and configured Rserve for Tableau.
In our next chapter, we will learn more about the underlying data structures of R so that we can make use of the analytic power of Tableau and R more effectively.