R闪亮内的离线传单

Jak*_*ake 5 r leaflet shiny

是否可以在Shiny应用程序中加载离线/本地传单地图图块?我能够如图所示加载瓷砖在交互式R对话在这里,但我现在想尝试并加载它们用在一个闪亮的应用程序。这是到目前为止我所拥有的一个例子。我认为这与Shiny通过IP和端口运行有关,并且还需要通过IP和端口加载图块。我已经尝试了一些方法来更改IP和端口(使它们相同),如此处所述但是还没有发现任何可行的方法。我也可以使用在线磁贴来使它工作,但是我需要它与本地地图磁贴一起工作。

library(shiny)
library(leaflet)
library(RColorBrewer)
library(RgoogleMaps)

options(shiny.port = 8000)

  (bwi <- getGeoCode("BWI;MD"))

df <- as.data.frame(rbind(bwi))
df$col <- c("orange")
df$name <- c("BWI")

icons <- awesomeIcons(
  icon = 'ios-close',
  iconColor = 'black',
  library = 'ion',
  markerColor = df$col
)
#################################################################################

ui <- bootstrapPage(
  tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
  leafletOutput("map", width = "100%", height = "100%"),
  absolutePanel(top = 10, right = 10,
                style = "padding: 8px; background: #FFFFEE; opacity:.9",
    checkboxInput("markers", "Show Markers?", TRUE)
  )
)    
#################################################################################

server <- function(input, output, session) {

  output$map <- renderLeaflet({
    leaflet() %>% 
      addTiles(urlTemplate = "http:/localhost:8000/C:/Users/OTAD USER/Documents/mapTiles/ESRIWorldTopoMap/{z}_{x}_{y}.png") %>%
      setView(lat = bwi[1], lng = bwi[2], zoom = 8)
  })

  observe({
    proxy <- leafletProxy("map", data = df)

    # Remove/show any markers
    proxy %>% clearMarkers()
    if (input$markers) {
      proxy %>% addAwesomeMarkers(lat = df$lat, lng = df$lon,
                                  icon = icons, label = df$name)
    }
  })
}

#Put the ui and server together and run
runApp(shinyApp(ui = ui, 
         server = server), launch.browser=TRUE
)
Run Code Online (Sandbox Code Playgroud)

Hub*_*rtL 5

1-您必须通过在资源上提供“别名”来授权Shiny在该文件夹中提供图块 addResourcePath

2-然后使用该别名作为 addTiles

server <- function(input, output, session) {
    addResourcePath("mytiles", "C:/Users/OTAD USER/Documents/mapTiles/ESRIWorldTopoMap")
    output$map <- renderLeaflet({
      leaflet() %>% 
        addTiles(urlTemplate = "/mytiles/{z}_{x}_{y}.png") %>%
        setView(lat = bwi[1], lng = bwi[2], zoom = 8)
    })
...
Run Code Online (Sandbox Code Playgroud)