leafletProxy出错:找不到函数“startsWith”

时间:2017-04-04 18:39:23

标签: r rstudio shiny

以下是我闪亮的代码。我希望这个应用程序允许用户点击地图并在响应(即观察事件)中点击,我希望地图显示标记。

 library(shiny)
 library(maps)
 library(stringi)
 library(ggmap)
 library(leaflet)

 ui <- shinyUI(bootstrapPage(
   tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
   leafletOutput("map", width = "100%", height = "100%")
 ))

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

## Make your initial map
output$map <- renderLeaflet({
leaflet() %>%
  setView(lng = -4, lat= 52.54, zoom = 7) %>%
addProviderTiles(providers$Stamen.TonerLite,
                 options = providerTileOptions(noWrap = TRUE))
})

## Observe mouse clicks and add marker
observeEvent(input$map_click, {
click <- input$map_click
clat <- click$lat
clng <- click$lng
text<- paste("Lattitude", click$lat, "Longtitude", click$lng)

proxy <- leafletProxy("map")
proxy %>% clearPopups() %>%
  addPopups(click$lng, click$lat, text) %>%
  addMarkers(lng=clng, lat=clat, popup = as.character(text), label = as.character(text))
})

})

runApp(shinyApp(ui, server), launch.browser = TRUE) 

我收到以下错误。

 Warning: Error in leafletProxy: could not find function "startsWith"
 Stack trace (innermost first):
 66: leafletProxy
 65: observeEventHandler [#22]
 1: runApp

0 个答案:

没有答案