10 Replies Latest reply on Apr 13, 2018 6:46 AM by Mainak Sen

# connection of tableau with R

Hi

I am new to Tableau and this community and  so pardon me if I am unable to understand any answer on the first attempt.

My requirement is to do factor analysis on a dataset in R and get back the factor loadings (which is a vector) as return and all this to be done in tableau. how to do that and whether I have to load the dataset in tableau or I can load it in R and call it from tableau. Factor should be 1 and method of factor analysis to be used is Principal component Analysis. The dummy data is attached. Please help.

• ###### 1. Re: connection of tableau with R

Hi Maniak,

First you have to allow Tableau to get Data from R.

Second you should bare in mind that tableau take from your Data Set with R script.

Pls follow this link. How to Integrate R and Tableau

Pls mark my response as correct and helpful, following this topic. So Your Question Didn't Get Answered...

D

• ###### 2. Re: connection of tableau with R

Hi

Thanks for the reply. But I already did all these steps. Now what I am facing is to get a vector from R into Tableau as return.

• ###### 3. Re: connection of tableau with R

You can only get a vector from R. May be you didn't apply vectors of the same length as columns in Tableau.

D

• ###### 4. Re: connection of tableau with R

Hi

SCRIPT_REAL("

library(psych)

df <- data.frame(.arg1,.arg2,.arg3,.arg4,.arg5,.arg6)

pc <- principal(df, nfactors=1)

pc\$loadings",

SUM([C1 1]),SUM([C2 1]),SUM([C3 R1 1]),SUM([C3 R2 1]),SUM([C3 R3 1]),SUM([C4 1])

)

When I am giving the above code for factor analysis in tableau then I am getting the below error message in return.

"An error occurred while communicating with the RServe service.

Error in principal(df, nfactors = 1) : I am sorry: missing values (NAs) in the correlation matrix do not allow me to continue. Please drop those variables and try again."

I have seen the data. There is no missing value in my data and I don't want to remove any of the variable.

• ###### 5. Re: connection of tableau with R

what's loading?

which arguments is it for tableau?

how will it be determine it from 6 other arguments?

D

• ###### 6. Re: connection of tableau with R

This is a factor analysis code. Loading is the factor analysis loadings for each factor. The arguments are the variables from the dataset which are passed as parameters at the end of the code.

• ###### 7. Re: connection of tableau with R

HI Mainak,

Try to bring one more variable from Tableau datasource.

D

• ###### 8. Re: connection of tableau with R

Hi

I have brought all the variables as input from tableau datasource. There is no other variable left. But still I am facing the error.

• ###### 9. Re: connection of tableau with R

Hi Mainak,

You dataset has 3000 rows, but the pc\$loadings is a vector of 6.

Tableau is expecting to have the result vector the same length as an input one.

So you may want to try using this calc instead:

SCRIPT_REAL("

library(psych)

df  <- data.frame(.arg1,.arg2,.arg3,.arg4,.arg5,.arg6)

pc  <- principal(df, nfactors=1)

c(pc\$loadings, rep(NA, length(.arg1) - length(pc\$loadings) ) )  ",

SUM([C1 1]),SUM([C2 1]),SUM([C3 R1 1]),SUM([C3 R2 1]),SUM([C3 R3 1]),SUM([C4 1])

)

And of course, you'd be doing this in a dis-aggregated mode in Tableau:

Main Menu --> Analysis --> Aggregate Measures : OFF

Yours,

Yuri

• ###### 10. Re: connection of tableau with R

Thank you Mr. Yuri.

I am getting the result as a vector but the result is coming in ascending order. But I need the answer as the input is given.

For example If I gave C6, C7,C8, C23, C9(you can see the variables in the dataset uploaded)as the variable input then I should get the factor analysis loadings as return in this order only.

Please help