Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

R visual · leaflet (air route)

Hi!

 

I have tried to do a R visual with "maps", "geosphere" and "leaflet" packages, to draw a line route beetween two points, but PowerBI doesn't show anything, I only get this message: "No image was created. The R code didn't result in creation of any visual. Make sure your R script results in a plot to the R default device".

 

The data is quite simple (is just an example):

 

 

 

 

Code from PowerBi's R scipt editor:

 

#Create dataframe

dataset <- data.frame(RUTA, ORIGEN, LAT1, LON1, DESTINO, LAT2, LON2)

 

#libraries

library(maps)
library(geosphere)
library(leaflet)

 

# geo-code

gcIntermediate(c(dataset[1,]$LON1, dataset[1,]$LAT1), c(dataset[1,]$LON2, dataset[1,]$LAT2),n=100,
addStartEnd=TRUE,
sp=TRUE) %>%
leaflet() %>%
addTiles() %>%
addPolylines()

 

In the other hand, if I run the script in R-Studio I get the map:

 

 

R code:

 

# Input load. Please do not change #
`dataset` = read.csv('xxx.csv', check.names = FALSE, encoding = "UTF-8", blank.lines.skip = FALSE);

library(maps)
library(geosphere)
library(leaflet)

gcIntermediate(c(dataset[1,]$LON1, dataset[1,]$LAT1), c(dataset[1,]$LON2, dataset[1,]$LAT2),n=100, 
               addStartEnd=TRUE,
               sp=TRUE) %>% 
  leaflet() %>% 
  addTiles() %>% 
  addPolylines()

Thank you very much,

Luis