I didn't find an option to disable the double click zoom in the R leaflet
package. So I tried to disable this option by passing JavaScript
code as strings to the shiny
web app.
You can try the reproducible example below.
library(leaflet)
# Make Leaflet map with JavaScript
# // Leaflet providers
leafletProviders <- "var OpenStreetMap_Mapnik = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19
});"
# // Map definition
map <- "var map = L.map('map', {
center: [-34.7247, -56.1237],
zoom: 8,
layers: [OpenStreetMap_Mapnik]
});"
# // Basemaps
baseMaps <- "var baseMaps = {'OpenStreetMap': OpenStreetMap_Mapnik};"
# // Add a layer control element to the map
layerControl <- "layerControl = L.control.layers(baseMaps, null, {
position: 'topleft'});
layerControl.addTo(map);"
ui <- fluidPage(
leafletOutput("map"),
HTML(paste("<script>", "\n", leafletProviders, "\n", map, "\n", baseMaps, "\n", layerControl,"\n", "</script>", sep = "")), # Make map JS code
HTML("<div id='divHtml' class='shiny-html-output'></div>") # Create empty div with known ID
)
server <- function(input, output, session) {
output$divHtml <- renderUI({
interaction <- "map.doubleClickZoom.disable();" # Modify interaction with map
mapHtml <- HTML(paste("<script>", interaction, "</script>", sep = "")) # Put JS code for interaction with created map in created DIV element
return(mapHtml)
})
}
shinyApp(ui, server)