-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pin doesn't load when using google_map_update #274
Comments
notes:
I've stripped down your example; you can see the output of the two library(shiny)
library(googleway)
key <- "key"
set_key(key = key)
ui <- shiny::basicPage(
div(
textInput(inputId = "my_address", label = "Type An Address")
, actionButton(inputId = "btn", "Search")
, shiny::tags$head(
shiny::tags$script(
'
var mapExists = setInterval(function() {
if(typeof google !== "undefined") {
clearInterval(mapExists)
var autocomplete = new google.maps.places.Autocomplete(document.getElementById("my_address"));
autocomplete.addListener("place_changed", function() {
autocomplete.setFields(["place_id", "geometry", "name"]);
var place = autocomplete.getPlace();
Shiny.setInputValue("jsPlaceAutocomplete", place);
});
}
}, 100);
'
)
)
,google_mapOutput(outputId = "my_map")
)
)
server <- function(input, output) {
observeEvent(input$jsPlaceAutocomplete, {
print(input$jsPlaceAutocomplete)
res <- input$jsPlaceAutocomplete
df <- data.frame(
lng = res$geometry$location$lng
, lat = res$geometry$location$lat
)
googleway::google_map_update(map_id = "my_map") %>%
googleway::add_markers(
data = df,
lat = "lat",
lon = "lng",
update_map_view = T
)
})
observeEvent(input$btn, {
print(input$jsPlaceAutocomplete)
})
output$my_map <- renderGoogle_map({
google_map(
location = c(-27.481080541187133, 153.0122871294947),
zoom = 16,
map_type_control = FALSE,
zoom_control = FALSE,
street_view_control = FALSE
)
})
}
shinyApp(ui, server) |
Thanks @dcooley Dave for taking the time. Exciting news about v3.0.0!! looking forward to it :) I was able to replicate this error by using the browser's dev tools and setting the option "Disable cache" on under the network menu. Note that this option only gets applied while dev tools is open. If I reload the app (page refresh) then I don't get this error and the app works as expected. |
I've updated This works for me without console errors, with 'disable cache' checked. ui <- shiny::basicPage(
div(
textInput(inputId = "my_address", label = "Type An Address")
, actionButton(inputId = "btn", "Search")
, shiny::tags$head(
shiny::tags$script(
'
var mapExists = setInterval(function() {
if(typeof google !== "undefined") {
if(typeof google.maps !== "undefined") {
clearInterval(mapExists);
var autocomplete = new google.maps.places.Autocomplete(document.getElementById("my_address"));
autocomplete.addListener("place_changed", function() {
autocomplete.setFields(["place_id", "geometry", "name"]);
var place = autocomplete.getPlace();
Shiny.setInputValue("jsPlaceAutocomplete", place);
});
}
}
}, 100);
'
)
)
,google_mapOutput(outputId = "my_map")
)
) |
Hi @dcooley , Thank you very much for your support here. Looking forward to version 3.0 |
I'm using googleway in an app that has an autocomplete search box outside the map. The first time the app loads and you search for an address it updates the map but it doesn't place the pin on the map, however, after one refreshes the page and search for an address again it works fine and the pin is placed. I've been able to reproduce the error with the following reprex below. Note that it needs to be run with the browser's developer tools open and option 'Disable cache' checkbox activated so it simulates the first load of the page. I think it has to do with the library loading process at start but I'm not sure. Any ideas I could try?
For example: searching for this address 25 Lang Street, Sunnybank Hills returns this
The js errors in the console are:
Any ideas would be much appreciated.
The text was updated successfully, but these errors were encountered: