Leaflet map tiles from url template not rendering in Shiny app

Viewed 578

I am trying to use the map.geo.admin tiles in leaflet.

When running

url <- 'https://wmts20.geo.admin.ch/1.0.0/ch.swisstopo.pixelkarte-farbe/default/current/3857/{z}/{x}/{y}.jpeg'

library(leaflet)
options(viewer = NULL)

leaflet() %>%
  setView(lat = 47, lng = 9, zoom = 8) %>%
  addTiles(urlTemplate = url)

the map is shown correctly in the browser (it does not work in RStudio Viewer pane),

enter image description here

but when I put the code inside a shiny app I get only a grey map (sometimes it is initially shown, but when I start zooming it greys out):

 library(shiny)

ui <- fluidPage(
  leafletOutput("map")
)

server <- function(input, output, session) {
  output$map <- renderLeaflet({
    leaflet() %>%
      setView(lat = 47, lng = 9, zoom = 8) %>%
      addTiles(urlTemplate = url)
      # addTiles()
  })
}

shinyApp(ui, server)

enter image description here

1 Answers
Related