I try to display the France map on HTML with RStudio; I followed the tutorial to the World card in Creating an interactive map with Leaflet; Example works.

I wanted to do the same just by displaying the map of France: code:



# Nettoyage des données

## Initialisation 
m <- leaflet(padding = 0)
## Ajout des pays

## Ajout des pays
m <- addPolygons(map = m, data = FRA, opacity = 100, 
                 color = "#FAFCFA", 
                 weight = 0.25,popup = NULL,
                 options = list(clickable = FALSE), 
                 fill = T, fillColor = "#B3C4B3", 
                 fillOpacity = 100)

## Dimensions de la carte
m$width <- 874
m$height <- 700

# Export de la carte en html
saveWidget(m, 'mapfrance.html', selfcontained = TRUE)


Stack space overflow: current size 33632 bytes.
Use `+RTS -Ksize -RTS' to increase it.
Erreur : pandoc document conversion failed with error 2

I do not understand this error, is that it's the input file is shapefile .shpaand not .rdata?

  • 1
    This should be fixed with the latest htmlwidgets package. Try updating and/or installing from github. If you still get an error (I do not btw) then you can set the pandoc.stack.size option mentioned here: github.com/ramnathv/htmlwidgets/commit/… – hrbrmstr Nov 28 '15 at 18:30

Try to set the selfcontained variable to FALSE. That worked for me. Beside that make sure that the Shape of France is saved with the coordinate system WGS 84 (EPSG:4326).

# install packages
install.packages(c("rgdal", "maptools", "leaflet", "htmlwidgets"), dependencies = TRUE)

# load libraries

# load france as shape

# Initialsation
m <- leaflet(padding = 0)

# Add country
m <- addPolygons(map = m, data = FRA, opacity = 100, 
                 color = "#FAFCFA", 
                 weight = 0.25,popup = NULL,
                 options = list(clickable = FALSE), 
                 fill = T, fillColor = "#B3C4B3", 
                 fillOpacity = 100)

# Dimention of the map
m$width <- 874
m$height <- 700

# Export as HTML file
saveWidget(m, 'mapfrance.html', selfcontained = FALSE)

leaflet france


After the hint of @hrbrmstr above I check my package version:

[1] ‘0.5’
| improve this answer | |

In case you do not mind about background maps, maybe you want to have a look at mapview (although the package does not support automated storing of created maps yet).

## required packages

## get shapefile
FRA <- getData(country = "FRA", level = "0")

## create interactive map
m <- mapview(FRA)


For now, the best workaround to retrieve the created map is to locate the temporary folder where all the output from your mapview() call is stored. You can type tempfile() into the R console to figure out the general path to the temporary folders created from R (on my linux machine it looks like this - "/tmp/RtmpzMzJv7/file..."). There you should find a folder that was created by mapview() (they are usually called something like "viewhtml..." with "..." being some random string of numbers and letters). There you should find an "index.html" file and one or more folders. You can simply copy all contents to a folder of your liking and open "index.html" from there.

Unfortunately, function plainview - which creates maps without displaying background maps - currently supports 'Raster*' objects only, but we hope to implement a version for polygons (and all other kinds of shapefiles) soon.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.