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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

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
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

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.