Open trafficonese opened 4 months ago
The htmlDependency is the right approach, I would think. Can you show me what you tried?
I tried some variations of this:
map$dependencies <- c(map$dependencies,
leafletSearchDependencies(),
list(htmltools::htmlDependency(
"googlesearchapi", "0.0.1",
src = c(href = url),
script = "js?v=3",
all_files = FALSE
)))
actually, that seems to works and the error must be somewhere else.. The script tag with the URL + APIKEY gets appended add the end of the head-tag.
Thank you for your time!
I did some further testing and downloaded the Javascript into www/google.js
that you get with this URL:
https://maps.googleapis.com/maps/api/js?v=3&key=API_KEY
This worked and the HTML head looked like this:
When using htmlDependency
(I tried different orders)
map$dependencies <- c(
list(htmltools::htmlDependency(
"googlesearchapi", "0.0.1",
src = c(href = url),
script = "",
all_files = TRUE
)),
map$dependencies,
leafletSearchDependencies()
)
I get the following errors:
and the head-tag looks like this:
I am not sure how I can control the order of the scripts or why not all google JS files get downloaded..
This is maybe more a question for htmltools
or?
Can you try installing shiny 1.7.5.1? That will tell us if the async related changes to renderContent are causing this (I’m almost certain they are).
Still no success with shiny 1.7.5.1. (Also no luck with 1.7.4)
The html head looks identical to the one above (using htmlDependency
).
Somehow the scripts log.js
and geocoder.js
are not included.
I took over maintenance of
leaflet.extras
and ran into this "bug" where I can't attach a script tag with the Google URL + API key.This line is the problem: https://github.com/trafficonese/leaflet.extras/blob/master/R/search.R#L210
I tried to add it as a
htmlDependency
, but then I get another error in the browser console, thatgoogle
is not defined.What is now the correct way of doing this? Or is that strictly forbidden, because of security concerns or the new async shiny way?