Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in BI by (17.6k points)

I would like to know how to use table data as a parameter in Tableau's R integration.

Example

Tableau has a builtin data set called "Superstore" used for reproducible examples. Suppose I've used the Superstore data set to create a "text table" (i.e. spreadsheet) with Region as rows and SUM(Profit) as the data.

That looks like this:

enter image description here

Now, suppose I wanted to pass the data in this table to R for a calculation. I would start Reserve

library(Rserve)

Rserve()

and establish a connection with Tableau's UI.

Next, I would want to create a calculated field to send the data to R and retrieve the results. I'm not sure how to do this.

My attempt looks like this:

SCRIPT_REAL('

    output <- anRFunction(.arg1)

',

[someTableauMeasure])

 

which should be fine, except that I don't know how to represent the table data where it currently says someTableauMeasure. This is just an arbitrary example, but a reason I might want to do this is that I might provide the user with a filter, such as Country, so that they could filter the results at will and get an updated result from R. 

For testing purposes that function anRFunction could be replaced with something like abs.

1 Answer

0 votes
by (47.2k points)
  • Aggregated values to R by Tableau, depending on the settings of your worksheet.

  • So in your case if you use:

SCRIPT_REAL(' output <- anRFunction(.arg1) ', sum(Profit))

  • You will get the output according to the dimensions you have on your worksheet, in your case [Region] if you set up a filter by country, R will only receive and return the values for a certain country and if you choose to use [Category] instead, you will get the results of your R function broken down by category.

Related questions

0 votes
1 answer
asked Jul 30, 2019 in BI by Vaibhav Ameta (17.6k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...