在 R Shiny 的 Leaflet 中移动缩放控件

Move zoom controls in Leaflet for R Shiny

我有一个包含多个传单地图的 Shiny 应用程序。我想将缩放 in/out 控件从地图的左上角移动到右上角,但我不确定该怎么做 - 我很确定这是通过调用 options = leafletOptions()leaflet()/leafletProxy() 中,但我不确定确切的语法。

最小可重现示例:

library(shiny)
library(leaflet)

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

server <- function(input, output) {
  output$output1 <- renderLeaflet({
    leaflet() %>%
      addProviderTiles(providers$Esri.WorldImagery)
  })
  

}

# Run the application 
shinyApp(ui = ui, server = server)

看这个例子:

library(shiny)
library(leaflet)
library(htmlwidgets)

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

server <- function(input, output) {
  output$output1 <- renderLeaflet({
    leaflet(options = leafletOptions(zoomControl = FALSE)) %>%
      addProviderTiles(providers$Esri.WorldImagery) %>%
      onRender(
        "function(el, x) {
          L.control.zoom({position:'topright'}).addTo(this);
        }")
  }) 
}
 
shinyApp(ui = ui, server = server)

代码引用了这个:https://markusdumke.github.io/articles/2017/11/customize-leaflet-map-in-r-with-html-css-and-javascript/