1

Problem

I have a data.frame that contains a column, named "icon", with a link in character format exactly like so "https://i.stack.imgur.com/kDNdX.png".

I am feeding the column name into the google_map_update call in my shiny app:

output$map <- renderGoogle_map({
      google_map(
        location = c(43.761539, -79.411079),
        key = api_key,
        scale_control = F,
        street_view_control = F
      ) 
    })

  observeEvent(
    input$updateData,  # a button that updates the data 
    {              

      googleway::google_map_update(map_id = "map") %>%
        clear_markers() %>%
        googleway::add_markers(
          lat = "lat.x",
          lon = "long.x",
          marker_icon = "icon", 
          data = data %>% filter(gender %in% input$gender)
     }
  )
)

However, when I plot the points, nothing shows. Looking at the Chrome console, I see error 404, url not found error. I can still see the clustered points (the yellow, red and blue signals with a number), but not the individual markers.

I tried the following

  1. Not including the s in https://
  2. Referring to a local file instead, calling it in 2 ways: absolute and relative
  3. Using an entirely different link that other sites use (http://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png)
  4. Looking at SO, but most google map marker question are in Javascript
  5. When using it non-shiny, the custom markers work:
google_map(
  location = c(43.761539, -79.411079),
) %>%
googleway::add_markers(
  data = data,
  marker_icon = "icon",
  lat = "lat.x",
  lon = "long.x",
  cluster = T
)
Robert Tan
  • 634
  • 1
  • 8
  • 21

1 Answers1

1

I can't replicate your error. Here's a working example where the markers are being updated, but keeping the icon value

library(shiny)
library(googleway)

ui <- fluidPage(
  google_mapOutput(outputId = "map", height = "800px"),
  actionButton(inputId = "btn", label = "some people")
)

server <- function(input, output) {

  tram_stops$icon <- "http://i.imgur.com/UxVFMcQ.png"
  # set_key("YOUR_GOOGLE_API_KEY)

  output$map <- renderGoogle_map({
    google_map(data = tram_stops) %>%
      add_markers(lat = "stop_lat", lon = "stop_lon", marker_icon = "icon")
  })

  observeEvent(input$btn, {

    myRow <- sample(1:nrow(tram_stops), 10)

    google_map_update(map_id = "map") %>%
      clear_markers() %>%
      add_markers(data = tram_stops[myRow, ], marker_icon = "icon")
  })
}

shinyApp(ui, server)

This opens with a map of custom markers

enter image description here

Then pressing the some people button samples ten rows of data, then uses google_map_update to update the existing map

enter image description here

enter image description here


devtools::session_info()
Session info -------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.4.4 (2018-03-15)
 system   x86_64, darwin15.6.0        
 ui       RStudio (1.1.447)           
 language (EN)                        
 collate  en_AU.UTF-8                 
 tz       Australia/Melbourne         
 date     2018-05-03                  

Packages -----------------------------------------------------------------------------------------------------
 package     * version date       source                          
 base        * 3.4.4   2018-03-15 local                           
 ...<snip>...                
 googleway   * 2.6     2018-04-29 local                           
 shiny       * 1.0.5   2017-08-23 cran (@1.0.5) 
SymbolixAU
  • 25,502
  • 4
  • 67
  • 139
  • Thank you Symbolix team. Your code works so it must be something else on my end, I'll experiment further and will report back with results. I updated the first chunk of code with more of my current code to show I'm updating an existing map – Robert Tan May 03 '18 at 03:31
  • I solved the issue, it was unrelated to your package. In an attempt to speed up the map_update, I used select() to select only a few columns (lat,long,info_window) of my data, forgetting to add "icon" to it. I'll delete this question tomorrow - my apologies for taking your time – Robert Tan May 03 '18 at 14:28
  • @RobertTan It might be useful to other people if you want to leave it up. Up to you though. – SymbolixAU May 04 '18 at 01:17