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
danthu
Helper I
Helper I

Display results from a machine learning output in R

Hi,

 

I have built a machine learning model in RStudio based on data exported from PowerBI Desktop. Now that I have my model I would like to use it for classifying new data points as they arrive after refreshing the data in PowerBI. Then I would like to either store the results in a new table in PowerBI that I can use for visualisations or use the R output directly for visualisations. 

 

As I understand it I should be able to use the functionality to base a PowerBI visualisation on a R script to do this. The problem is, if I just copy my R code into PowerBI it will train a new model based on the updated data each time I refresh the data in PowerBI, right? I do not want to retrain my model, I just want to use the already trained model for doing predictions on yet unlabelled data. Is it possible to let PowerBI use my already trained model without running through the entire script and thus retraining the model on new data?

 

 

4 REPLIES 4
v-sihou-msft
Microsoft Employee
Microsoft Employee

@danthu

 

No, it's not possible to let your R script running in Rstudio and only export the result into Power BI Desktop. You have to run extire R script in Power BI Desktop. And I don't know what package you are using for machine learning. Please refer to this document to see if it is supported in Power BI.

 

Regards,

Thank for your reply. I am using the caret package for machine learning which should be supported?

 

I understand that I have to run the entire code in PowerBI however I'm trying to figure out if it is possible to use a model that I have allready trained and npt having to retrain the model each time I want to do a prediction.

 

I have the model object stored as a .rda file. I can load that model in RStudio with load() without any problems. But when I try to do load() in PowerBI it can't find or open the model object. Also in the PowerBI R query when I try to load data from a .csv file with read_csv() it cannot find the file. I have tried placing the files both in my RStudio working directory and in the R home directory specified by PowerBI.

 

Can anyone explain why I get this error?

I solved the prolem of loading files in the script. I just had to set the working directory specifying the full path instead of relative.

 

However now I have encountered another error message:

 

We encountered an error while trying to connect.

Details: "Unable to translate bytes [E4] at index 0 from specified code page to Unicode."

 

Can anyone explain to me what this means?

Anonymous
Not applicable

thanks, this worked for me in pbi desktop.

but not in pbi service. is it possible to load an rds file in service?

 

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.