Hi,
First of all this is a great package, it's easy to grab the map bounds and zoom level, among other features. However, I am having difficulty dynamically changing the initialTileLayer using shiny-leaflet.
I have created a minimal example using two different initialTileLayer's. It seems to require two corresponding maps in server.R. Here is the ui.R:
library(shiny);library(leaflet)
shinyServer(function(input, output, session) {
output$map1 <- reactive(TRUE)
map1 <- createLeafletMap(session, "map1")
output$map2 <- reactive(TRUE)
map2 <- createLeafletMap(session, "map2")
})
It also requires a styles.css in the same directory as server.R and ui.R:
div.outer {
position: fixed;
top: 41px;
left: 0;
right: 0;
bottom: 0;
overflow: hidden;
padding: 0;
}
Here's the ui.R:
library(shiny);library(leaflet)
shinyUI(navbarPage("Switch Map",
tabPanel("Map",
conditionalPanel(
condition = "input.bmappick == 'MapQuestOpen.Aerial'",
div(class="outer",tags$head(includeCSS("styles.css")),
leafletMap("map1", "100%", "100%",
initialTileLayerAttribution =
Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency'),
options=list(center = c(40, -98.85),zoom = 5)))),
conditionalPanel(
condition = "input.bmappick == 'OpenStreetMap'",
div(class="outer",tags$head(includeCSS("styles.css")),
leafletMap("map2", "100%", "100%",
initialTileLayerAttribution =
options=list(center = c(40, -98.85),zoom = 5)))
),
absolutePanel(top = 60, left = "auto", right = 20, bottom = "auto",
selectInput("bmappick", "Background Map",c("OpenStreetMap" = 'OpenStreetMap',
"MapQuestOpen.Aerial"= 'MapQuestOpen.Aerial'),selected = c("OpenStreetMap")))) ))
The background map that is not selected first by default through "bmappick" never fills the entire screen and appears to be a single tile. Is there a way to do this? I greatly appreciate any help.
Regards,
Chris
P.S. to install leaflet-shiny:
if (!require(devtools))
install.packages('devtools')
devtools::install_github('leaflet-shiny', 'jcheng5')