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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Panou
Regular Visitor

Load external map files into R script

Hi, 

 

I'm testing R visual in PowerBI (I'm a beginner in R). I use map files from an external direectoy which works fine in PowerBI Desktop. However, after uploading the report into PowerBI, I can't access my local files. Not sure how to access these files from PowerBI Service? Could I get them from OneDrive?

 

I set the files directory this way in my R code:

 

MapDir <-"C:/Tuna_dbs/R_Maps/"
 
And then access a .shp file :
 
fnam.eez.world.v11 <- "eez_boundaries_v11.shp"

 

Any help would be welcome.

 

Many thanks

2 REPLIES 2
Jsanua
New Member

If you're ok with using an R script as a query source , you could import the shapefile in an R query and convert the geometry into a well known text (wkt) column (using the sf package's st_as_text() function). This stores the geometry as plain text for each feature.

 

R Script Query example

library(sf)
shp <- st_read(shapefile)
shp$wkt <- st_as_text(shp$geometry)


When you're ready to do the visual, you can add that wkt column from the PowerBI table to your script visual and convert it back to a spatial format by using st_as_sf(). Make sure your wkt text column is both not summarized and Show items with Missing Data is checked.

 

Script Visual code to convert wkt column back to sf

library(sf)
dataset_sf <- st_as_sf(dataset, wkt = "wkt", crs = 4326)


I'm assuming your shapefile is WGS84 projection (SRID 4326), but set your CRS argument accordingly to the original projection.  

Note that for scheduled refresh on the PowerBI service requires a personal gateway for queries using R scripts as sources.  

v-easonf-msft
Community Support
Community Support

Hi, @Panou 

You can try to change the path to the cloud, or install a personal gateway.

I am not sure about that. You can open a support ticket with MSFT to seek technical support ,they will have better suggestions.

Related document:
https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-r-in-query-editor 

 

103.png

 

Best Regards,
Community Support Team _ Eason

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.

Top Solution Authors