Does anyone know how to set default render zoom of a Shiny Leaflet map so a full world map zooms to fit the window width (i.e. -180° to 180° properly fits the window)? I can only set zoom to integers, with 2
being too small and 3
too big. Reproducible example:
require(shiny)
require(leaflet)
require(magrittr)
d = data.frame(country = c('China', 'Brazil', 'Canada'), lon = c(105, -52, -95), lat = c(35, -10, 60))
server <- function(input, output, session) {
output$mymap <- renderLeaflet({
leaflet(d) %>%
addCircleMarkers(layerId = ~country, lng = ~lon, lat = ~lat, label = ~ country, radius=30) %>%
addProviderTiles(providers$Stamen.TonerLite, options = providerTileOptions(noWrap = TRUE, minZoom=1, maxZoom=18)
)
})
}
ui <- fluidPage(
tags$head(tags$style(HTML("#mymap { position: fixed; left: 0; top: 0; width: 100vw; height: 100vh !important; }"))
),
leafletOutput("mymap")
)
shinyApp(ui, server)