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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Panou
New Member

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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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