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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors