trafficonese / leaflet.extras

Extra functionality for leaflet R package.
https://trafficonese.github.io/leaflet.extras/
GNU General Public License v3.0
212 stars 74 forks source link

addSearchGoogle Not Working #112

Open chris-holcomb opened 6 years ago

chris-holcomb commented 6 years ago

Getting the following message. It shows the OSM search but not Google:

Warning in origRenderFunc() : Ignoring appended content; appendContent can't be used in a Shiny render call

library(shiny); library(shinydashboard); library(leaflet); library(leaflet.extras)

ui <- dashboardPage(
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(
  ),
  dashboardBody(
        leafletOutput(outputId = "mymap1", width ="100%", height = "900px")
  )
)

server <- function(input, output) {
  output$mymap1 <- renderLeaflet({
    leaflet() %>% addProviderTiles(providers$Esri.WorldStreetMap) %>% 
      setView(lng = 174.768, lat = -36.852, 9) %>% 
      addSearchOSM() %>% 
      addSearchGoogle(apikey = YOURAPIKEY)
  })

}

shinyApp(ui, server)

devtools::session_info():

leaflet * 1.1.0.9000 2017-10-30 Github (rstudio/leaflet@d489e2c) leaflet..extras * 0.2.9002 2017-10-30 Github (bhaskarvk/leaflet.extras@23de9ea) shiny * 1.0.5.9000 2017-10-30 Github (rstudio/shiny@ba8d79f)

bhaskarvk commented 6 years ago

Thanks, I will check it out.

ghost commented 6 years ago

Hi there, any updates on this? :)

jlbarr commented 6 years ago

Interested in the status on this.

bhaskarvk commented 5 years ago

I'll be resuming development of leaflet.extras in Dec and will tackle this in that round. Thanks!

urwa commented 4 years ago

Hi @bhaskarvk, I was planning to sign up for Google Business account, just for this feature to get the geocoding API key and I stumbled upon this open issue.

I already have signed up for MapQuest API but I wanted out-of-the-box solution for search bar on the leaflet map with autocomplete feature.

Given the addSearchGoogle() won't work, can you point out to the code for it, so may be I can try to replicate it for MapQuest API.

Apart from all this, thank you for your time and effort leaflet.extras has been very useful. Also, if you can point to the right direction, is there any way I can contribute to this project for this feature.

Thanks.

urwa commented 4 years ago

Also,

I looked at the code in search.R and the relevant part of code is addSearchGoogle <- function( map, apikey = Sys.getenv("GOOGLE_MAP_GEOCODING_KEY"), options = searchOptions(autoCollapse = TRUE, minLength = 2) ) { url <- "https://maps.googleapis.com/maps/api/js?v=3" if (is.null(apikey)) { warning("Google Geocoding works best with an apikey") } else { url <- paste0(url, "&key=", apikey) } map$dependencies <- c(map$dependencies, leafletSearchDependencies()) invokeMethod( map, getMapData(map), "addSearchGoogle", options ) %>% htmlwidgets::appendContent(htmltools::tags$script(src = url)) }

I partially understand the code. I would really love to make this work.

Looking forward to your response.

trafficonese commented 6 months ago

I opened an issue at Shiny https://github.com/rstudio/shiny/issues/3992