SymbolixAU / googleway

R Package for accessing and plotting Google Maps
http://symbolixau.github.io/googleway/
Other
234 stars 46 forks source link

Uncaught ReferenceError: google is not defined #258

Closed tnelsen closed 1 year ago

tnelsen commented 2 years ago

I am using the googleway package in several shiny applications and have been getting the error below over the past few weeks. It seems like the google_map.js file from the package is not being read properly. Is there a way to remedy this on my end? Thanks. image

dcooley commented 2 years ago

Are you using the CRAN or github (dev) version? Does this prevent the map loading?

tnelsen commented 2 years ago

We are using the dev version (2.7.6001). We are getting inconsistent behavior reported by our users with some reporting that the map is not loading. The map loads for me but I still get the ReferenceError.

dcooley commented 2 years ago

In the very latest version I've added an 'initialiser callback' in the javascript code, to let shiny know when the google object (map) is ready

Can you run this small example and see if you get the console error?

library(googleway)
library(shiny)

## set your key
# set_key(secret::get_secret("GOOGLE"))

ui <- fluidPage(
  googleway::google_mapOutput(
    outputId = "map"
  )
)

server <- function(input, output, session) {
  output$map <- googleway::renderGoogle_map({
    google_map()
  })

  observeEvent(input$map_initialised, {
    print(input$map_initialised)

  })

}

shinyApp(ui, server)
tnelsen commented 2 years ago

The map renders fine but I am still seeing the error: Uncaught TypeError: Cannot read properties of undefined (reading 'Map') at google_map.js:53:51

dcooley commented 2 years ago

did you get named list() printed to your R console?

tnelsen commented 2 years ago

Yes. That's the only thing that is printed in the R console. named_list()

tnelsen commented 2 years ago

If it's helpful to see an example, here's one of our applications that is getting these errors. https://gcsxgsestimate.herokuapp.com/

dcooley commented 2 years ago

In a new R Session, can you install the version that's on branch issue256 and let me know if you get the same console errors:

remotes::install_github("SymbolixAU/googleway", ref = "issue256")

and then run this small example again


library(googleway)
library(shiny)

set_key(secret::get_secret("GOOGLE"))

ui <- fluidPage(
  googleway::google_mapOutput(
    outputId = "map"
  )
)

server <- function(input, output, session) {
  output$map <- googleway::renderGoogle_map({
    google_map()
  })

  observeEvent(input$map_initialised, {
    print(input$map_initialised)
  })

}

shinyApp(ui, server)
tnelsen commented 2 years ago

I do not get the same/any errors on the minimal example above!

dcooley commented 2 years ago

ok that's progress! Any chance you can try it on one of your shiny's that's having issues?

tnelsen commented 2 years ago

I traced back the error to the geolocation returning NULL when the app is first loaded. On slower connections, this is more of an issue. I put a check in our apps to check if the geolocation is non-NULL and am no longer seeing the error anywhere.

dcooley commented 2 years ago

am no longer seeing the error anywhere.

Is this on the issue256 branch still, or are you saying you're no longer seeing the issue using the master branch?

tnelsen commented 1 year ago

We are no longer seeing the issue on either of the branches. I think the NULL check is what was needed to resolve the error :)