I am using Leaflet R package for rendering Leaflet map. I want to render my map with Canvas instead of SVG. For this to achieve I need to set preferCanvas flag to true in Leaflet Options. But I am not able to do so in Leaflet for R (map still renders in SVG). Here is the working demo of Canvas map with JavaScript.
Server.R:
output$map <- renderLeaflet({
leaflet(
options = leafletOptions(preferCanvas = TRUE)
) %>%
setMaxBounds(lng1 = -180, lng2 = +180, lat1 = -90, lat2 = +90)
})
observe({
if(!is.null(input$map_bounds)){
if(input$map_zoom<3){
boundsBuff<- input$map_bounds
leafletProxy("map") %>%
setView(lng=(boundsBuff$north + boundsBuff$south)/2,
lat=(boundsBuff$east + boundsBuff$west)/2,
zoom = 3
)
}
})
UI.R:
leafletOutput("map", width = "100%", height = "100%")
As per this Leaflet documentation, it seems I am doing it correctly but still it's not working, What I am doing wrong here?