Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
pk_123
Regular Visitor

Return a R dataframe

When using the R script, is there an option to return a dataframe as a table for display alongside another R visual?  So, I suppose that is really two questions 1) can a dataframe be returned from an R script and 2) can multiple objects be returned from an R script?

6 REPLIES 6
v-chuncz-msft
Community Support
Community Support

@pk_123,

 

Yes, you may take a look at the following post.

https://community.powerbi.com/t5/Developer/Create-tables-or-queries-with-R-script-for-further-usage/...

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

OK so that is how you make a dataframe in R. Thanks. That doesn't show me how this can be displayed as a visual in PowerBI if that R code is run in an R visual.

 

What I mean to ask was whether I could put a dataframe containing something like summary statistics alongside an R visual… Say I plot a scatter plot and I want to display a linear trend across the scatter plot with its slope coefficient etc. I want to use the slicer to change the date range over which the graph is generated. I think my only option to display summary statistics is to annotate the graph with text. What would be vastly superior is to display summary statistics in a separate table with formatting etc. It doesn’t seem like PowerBI supports something like this in so far as I can tell.

@pk_123,

 

It seems that you may use calculated columns and measures instead.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello,

 

I don't think that is what pk_123 meant. 

 

Making charts with R often includes making different aggregations / calculations and then storing the cals alongside the data in data frame, on which the visuals are built on. The cals are then shown inside the visual (e.g. "stripline / target value", or standard deviation, or capability indices alongside bar chart or capability histogram).

 

In my case I have built the same data frame and chart in both standalone R application and then inside R visual in Power BI. I calculate Cpk and Cp indices by groups in a data frame. in standalone R everything goes fine, but when I have exact same data and exact same script in Power BI R, I get an error 

 

df4$Cp <- df4$tol / (6 * df4$sdev)

" R script error. Error in '$<-.data.frame'('*tmp*', Cp, value = numeric(0)) :

replacement has 0 rows, data has 9

Calls:$<- ->$.data.frame

Execution halted

 

It would be nice to actually see the data frame built in power bi R in order to understand why this does not work. It works in standalone R.

Did anyone find a solution to return a table as an r visual in power bi?

Dear posters, did you find a solution? I have a similar issue and would like to know if there is a way to return a table from an R visual in power bi.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.