6 Replies Latest reply on Nov 14, 2013 10:15 AM by Jim Wahl

    Connecting to a data set in R from Tableau

    Anusua Singh Roy

      Hi

       

      I am running the server version of RStudio and would like to connect to a data set that is saved in my R workspace directly from Tableau.

       

      I am not sure what steps to follow after installing the Rserve package and setting up the connection within tableau with the help of 'Manage R Connection'.

       

      Any help on this would be highly appreciated.

       

      Thanks

      Anusua

        • 1. Re: Connecting to a data set in R from Tableau
          Matt Lutton

          Have you looked at the various tutorials available?  I don't use R regularly, but was able to connect and do some basics by following a couple of tutorials online:

          http://www.r-bloggers.com/dream-team-combining-tableau-and-r/

          Tableau 8.1 and R | Tableau Software

           

          This is the one I used: Impact Analytix: Business Intelligence, Predictive Analytics & Excel (scroll down the page to find the bit on R & Tableau)

           

          Not sure if any of these address your needs.  If you don't get any helpful responses here, you might try the 8.1 beta forum group: http://community.tableau.com/groups/tableau-81-beta-forum

          1 of 1 people found this helpful
          • 2. Re: Connecting to a data set in R from Tableau
            Anusua Singh Roy

            Thanks for your response.

             

            I have gone through these tutorials and what I gather is that you can pass parameters from tableau into R, perform some analysis and return the results back to Tableau to visualise - (not sure if I'm right in thinking this).

             

            However, I already have a data frame in R that I want to directly pass into Tableau (without having to download it as a CSV to my machine) and visualise thereafter. I cannot seem to find the appropriate function to do this.

             

            Cheers

            Anusua

            • 3. Re: Connecting to a data set in R from Tableau
              Matt Lutton

              I have no personal experience, but I would strongly suggest posting in the Tableau 8.1 forum group: http://community.tableau.com/groups/tableau-81-beta-forum

              • 4. Re: Connecting to a data set in R from Tableau
                Jim Wahl

                Hi Anusua,

                 

                I don't think this is directly possible, since Tableau's R integration is a table calculation, and table cacualtions, like other calculated fields, augment existing data sources with additional columns. They aren't designed to add data sources or to add rows to an existing data source.

                 

                There are a couple of workarounds:

                1. Use a scaffold and use R data frame indexes to fill in the scaffold.

                2. Have the Tableau-R calculated field save the data frame to a location accessible by Tableau.

                 

                Neither is optimal. Tableau will run these functions every time it refreshes the worksheet, which will slow you down. You might solve this for option 2 by only executing the function if a certain amount of time has passed or if a parameter is set to refresh.

                 

                Here's an example of the scaffold approach that "imports" R's mtcars data frame:

                2013-11-14 10-45-04.png

                 

                Start by creating a data source (text or excel) file with one column and the number of rows you have in your data source, in this case 32.

                RowNum

                1

                2

                3

                ...

                31

                32

                 

                Now you can create calculated fields.

                 

                Make and Model =

                SCRIPT_STR('data(mtcars)

                            rownames(mtcars)[.arg1]', MIN(RowNum) )

                 

                mpg =

                SCRIPT_REAL('data(mtcars)

                             mtcars$mpg[.arg1]', MIN(RowNum) )

                 

                And get this:

                2013-11-14 10-49-12.png

                 

                Jim

                • 5. Re: Connecting to a data set in R from Tableau
                  Anusua Singh Roy

                  Hi Jim

                   

                  Many thanks for your response.

                   

                  I tried to import a data that I had created in R as per your suggestion, but I got the error - Error in eval(expr, envir, enclos) : object 'tableau_data' not found. ['tableau_data' is a data frame that I created and saved in R]

                   

                  I am not sure why I got this error - does this mean that it can only import data sets that are available in R packages and not ones that are manually created ?

                   

                  Also, I tried the same using your example of the cars data and this is what I managed -

                   

                   

                  Tableau_Ex2.png

                   

                  Any idea where I'm going wrong ?

                   

                  Thanks

                  Anusua

                  • 6. Re: Connecting to a data set in R from Tableau
                    Jim Wahl

                    I am not sure why I got this error - does this mean that it can only import data sets that are available in R packages and not ones that are manually created ?

                    You'll need to run the same commands you normally run in your R session to load the data. Tableau is just running what you pass it in the calculated field, and you can include commands like load(...), ...

                     

                     

                     

                    Any idea where I'm going wrong ?

                     

                    If right-click the green mpg pill > Convert to discrete, it will change to blue, discrete pill and you'll get a tabular view.