Skip to content
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

Update google map location center in Shiny app #261

Closed
ssnyder20 opened this issue Nov 11, 2022 · 2 comments
Closed

Update google map location center in Shiny app #261

ssnyder20 opened this issue Nov 11, 2022 · 2 comments

Comments

@ssnyder20
Copy link

ssnyder20 commented Nov 11, 2022

Hello!

I am trying to update the center location of a google_map() based on a reactive input. Similar to the question asked here. I am doing this in an observeEvent with google_map_update by updating the markers. However, it updates the marker to the correct location, but the center location stays the same, and it zooms out so the map contains the location. I'd rather have the zoom stay fixed and the center updated to the lat/lon of the reactive input.

There also seems to be an easier solution using google_map_view, from the thread here. I'm using googleway 2.7.6 and it doesn't recognize that function. Has this been removed or renamed? Cause this seems to be a solution if it's still available.

Below is some code in my server.R:

  output$map <- renderGoogle_map({
    
    data <- csv %>% filter(name == rsrt())
    google_map(key = gkey, map_type = 'hybrid', data = data) %>%
      add_markers(lat = "lat", lon = "lon")
    
  })
  observeEvent(rsrt(),{

    data <- csv %>% filter(name == rsrt())
    google_map_update("map", data = data) %>%
      clear_markers()

    google_map_update("map", data = data) %>%
      add_markers(lat = "lat", lon  = "lon")

  })

Let me know if you have any insight. I appreciate the help!

@tnelsen
Copy link

tnelsen commented Mar 3, 2023

To use the update_map_view option within the add_markers function you have to have the dev version of the package (2.7.6001). It does seem like that option would fix your problem as well! Those changes were added after the most recent CRAN release (2.7.6).

@ssnyder20
Copy link
Author

To use the update_map_view option within the add_markers function you have to have the dev version of the package (2.7.6001). It does seem like that option would fix your problem as well! Those changes were added after the most recent CRAN release (2.7.6).

Awesome, that worked. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants