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

Ignoring appended content; appendContent can't be used in a Shiny render call #3992

Open
trafficonese opened this issue Mar 10, 2024 · 6 comments

Comments

@trafficonese
Copy link

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, that google 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?

@jcheng5
Copy link
Member

jcheng5 commented Mar 10, 2024

The htmlDependency is the right approach, I would think. Can you show me what you tried?

@trafficonese
Copy link
Author

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
                        )))

@trafficonese
Copy link
Author

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!

@trafficonese
Copy link
Author

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:
image

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:
image

and the head-tag looks like this:
image

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?

@jcheng5 jcheng5 reopened this Mar 10, 2024
@jcheng5
Copy link
Member

jcheng5 commented Mar 10, 2024

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).

@trafficonese
Copy link
Author

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.

My session info
─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
setting  value
version  R version 4.3.1 (2023-06-16 ucrt)
os       Windows 11 x64 (build 22631)
system   x86_64, mingw32
ui       RStudio
language (EN)
collate  German_Austria.utf8
ctype    German_Austria.utf8
tz       Europe/Vienna
date     2024-03-11
rstudio  2023.06.0+421 Mountain Hydrangea (desktop)
pandoc   3.1.1 @ C:\\PROGRA~1\\RStudio\\RESOUR~1\\app\\bin\\quarto\\bin\\tools\\pandoc.exe

─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
package           * version date (UTC) lib source
bslib               0.5.1   2023-08-11 [1] CRAN (R 4.3.1)
cachem              1.0.8   2023-05-01 [1] CRAN (R 4.3.1)
cli                 3.6.1   2023-03-23 [1] CRAN (R 4.3.1)
crosstalk           1.2.0   2021-11-04 [1] CRAN (R 4.3.1)
digest              0.6.33  2023-07-07 [1] CRAN (R 4.3.1)
ellipsis            0.3.2   2021-04-29 [1] CRAN (R 4.3.1)
fastmap             1.1.1   2023-02-24 [1] CRAN (R 4.3.1)
htmltools           0.5.6   2023-08-10 [1] CRAN (R 4.3.1)
htmlwidgets         1.6.2   2023-03-17 [1] CRAN (R 4.3.1)
httpuv              1.6.11  2023-05-11 [1] CRAN (R 4.3.1)
jquerylib           0.1.4   2021-04-26 [1] CRAN (R 4.3.1)
jsonlite            1.8.7   2023-06-29 [1] CRAN (R 4.3.1)
later               1.3.1   2023-05-02 [1] CRAN (R 4.3.1)
leaflet           * 2.2.0   2023-08-31 [1] CRAN (R 4.3.1)
leaflet.extras    * 1.0.0   2024-03-11 [1] local
leaflet.providers   1.13.0  2023-08-10 [1] CRAN (R 4.3.1)
lifecycle           1.0.3   2022-10-07 [1] CRAN (R 4.3.1)
magrittr            2.0.3   2022-03-30 [1] CRAN (R 4.3.1)
memoise             2.0.1   2021-11-26 [1] CRAN (R 4.3.1)
mime                0.12    2021-09-28 [1] CRAN (R 4.3.0)
promises            1.2.1   2023-08-10 [1] CRAN (R 4.3.1)
R6                  2.5.1   2021-08-19 [1] CRAN (R 4.3.1)
Rcpp                1.0.11  2023-07-06 [1] CRAN (R 4.3.1)
rlang               1.1.1   2023-04-28 [1] CRAN (R 4.3.1)
rstudioapi          0.15.0  2023-07-07 [1] CRAN (R 4.3.1)
sass                0.4.7   2023-07-15 [1] CRAN (R 4.3.1)
sessioninfo         1.2.2   2021-12-06 [1] CRAN (R 4.3.1)
shiny             * 1.7.5.1 2023-10-14 [1] CRAN (R 4.3.1)
withr               2.5.1   2023-09-26 [1] CRAN (R 4.3.1)
xtable              1.8-4   2019-04-21 [1] CRAN (R 4.3.1)

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