Hack-R Hack-R - 1 year ago 112
R Question

How to use table data as a parameter in Tableau's R integration?

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


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

as rows and
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 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:

output <- anRFunction(.arg1)

which should be fine, except that I don't know how to represent the table data where it currently says
. 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
, so that they could filter the results at will and get an updated result from R.

For testing purposes that function
could be replaced with something like

Answer Source

Tableau will pass the aggregated values to R, depending on the settings of your worksheet.

So in your case if you use:

    output <- anRFunction(.arg1)

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download