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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
davor
Regular Visitor

Published R reports with sourced scripts

Do I have an option to publish R scripts as well when publishing reports?

 

I would like to do:

source('path/to/script.r')

A workable option is to import the script files with 'Get Data' -> 'Folder', and then use something like:

eval(parse(text = as.character(dataset$Content[1])))

where 'Content' is the script file transformed to text. This is OK, as long as you don't pass lots of extra data due to the 'unique(dataset)' expression.

 

Obviously I could also paste the whole script, but from a code-re-use perspective it is bad practice (and the script is quite long...). 

 

Anyway, any decent way to load scripts, or am I to hack around it?

9 REPLIES 9
TomMartens
Super User
Super User

Hey,

currently it's not possible to reuse r-script files if you are using the r-script visual approach.

If you consider to create a r based custom visual then you are able to source r script files.
I guess this will get you started:
https://github.com/Microsoft/PowerBI-visuals/blob/master/Readme.md

But you have to be aware that there is still no global library that you can use for many visuals.

Hopefully this gets you started

Regards
Tom


Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi Tom, can you elaborate on:

 

"But you have to be aware that there is still no global library that you can use for many visuals."

Hey,

what I mean is this:

You can source script files, if you are creating a custom visual, but you to do it for each visual that you want to use your source file.

Meaning for each custom visual you are creating, you have to source file individually.

Hopefully this clarifies my first post a bit.

Regards
Tom


Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Any way to adjust the current R-script-visual (i.e. make a new one based on the CORE R-script-visual)?

 

I am mainly thinking about removing `unique(dataset)`.

Anonymous
Not applicable

Hi @davor. I have the same issue. Did you find a solution?

No.

 

I have one large script that I copy-paste in all the visuals, and then at the end only call those functions that are needed for the visual.

 

 

Best I could think of...

Anonymous
Not applicable

i found this solution on stack overflow

I also tried sourcing from the web:

source('https://raw.githubusercontent.com/.../model.r')

 

But it seems this is explicitely blocked:

Error in file(filename, "r", encoding = encoding): cannot open the connection 
In addition:
Warning message: In file(filename, "r", encoding = encoding):
InternetOpenUrl failed: 'The server name or address could not be resolved'  
davor
Regular Visitor

Each r-visual also seems to operate in its own VM environment, so if you export something to "C:\Reports" with one visual, the other visual doesn't see it in "C:\Reports".

 

If this was possible, one could use one visual to parse the code from "Get Data -> Folder", and the others could load it from "C:\Reports" when available with something like:

while (!file.exists('parsed.r')) {
  Sys.sleep(0.01)
}
load('parsed.r')

Pff, getting out of ideas...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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