I want to click a button to make a leaflet map and all overlayed inputs full screen.
Using the following example, I can make the map full screen but I lose the inputs (in this case, h1("test")
). Or I can preserve the inputs on top of the map but then the map is not drawn full screen as expected.
library(leaflet)
library(shiny)
js <- "
function openFullscreen(elem) {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) { /* Firefox */
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) { /* IE/Edge */
elem.msRequestFullscreen();
}
}"
ui <- fluidPage(
tags$scrip(HTML(js)),
actionButton("fullscreen", "Full Screen Container",
onclick = "openFullscreen(document.getElementById('map_container'))"),
actionButton("fullscreen", "Full Screen Map Only",
onclick = "openFullscreen(document.getElementById('map'))"),
div(
id = "map_container",
leafletOutput(height = "100px", "map"),
absolutePanel(
top = 20,
right = 20,
h1("test", style = "color:white")
)
)
)
server <- function(input, output, session) {
output$map <- renderLeaflet({
leaflet() %>%
addProviderTiles('Esri.WorldImagery') %>%
setView(lng = 118.2437, lat = 34.0522, zoom = 5)
})
}
shinyApp(ui, server)
Update
I tried adding z-index: 10000 !important;
to the h1()
style based on this, but it is still hidden when maximizing the leaflet map.