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

tagQuery(): Nested tagList() htmlDependency() values are being dropped #301

Closed
DavidJesse21 opened this issue Dec 4, 2021 · 1 comment · Fixed by #302
Closed

tagQuery(): Nested tagList() htmlDependency() values are being dropped #301

DavidJesse21 opened this issue Dec 4, 2021 · 1 comment · Fixed by #302

Comments

@DavidJesse21
Copy link

@DavidJesse21 DavidJesse21 commented Dec 4, 2021

Hi, I would like to use tagQuery() to create/modify tags like cards, navbars and panels that serve as containers for UI output.
I've already posted a detailed explanation of my problem including a reprex here:
https://community.rstudio.com/t/shiny-htmltools-custom-tags-behave-weird-when-using-tagquery-to-modify-tags/123308

Long story short, running tagQuery() on a tag, that somewhere contains an htmlwidget UI output, changes the structure of the tag, such that the UI output won't be shown anymore.
Weirdly, this is only the case, when you do this at least twice.

I hope you can tell what the problem is and help me out.

Thanks in advance and kind regards
David

@schloerke schloerke changed the title tagQuery(): Weird output/modufication of tags with htmlwidget output inside tagQuery(): Nested tagList() htmlDependency() values are being dropped Dec 6, 2021
@schloerke
Copy link
Collaborator

@schloerke schloerke commented Dec 6, 2021

tl/dr: tagQuery() is dropping html deps when squashing tagList()s within $children.

Reprex:

library(htmltools)

barret_dep <- htmlDependency(name = "barret", version = 1, src = list(file = "some/file.js"))

children <- attachDependencies(list("A", "B"), barret_dep)

html <- div("example", children)
tq_html <- tagQuery(html)$allTags()

# These should match
str(html)
#> List of 3
#>  $ name    : chr "div"
#>  $ attribs : Named list()
#>  $ children:List of 2
#>   ..$ : chr "example"
#>   ..$ :List of 2
#>   .. ..$ : chr "A"
#>   .. ..$ : chr "B"
#>   .. ..- attr(*, "html_dependencies")=List of 1
#>   .. .. ..$ :List of 10
#>   .. .. .. ..$ name      : chr "barret"
#>   .. .. .. ..$ version   : chr "1"
#>   .. .. .. ..$ src       :List of 1
#>   .. .. .. .. ..$ file: chr "some/file.js"
#>   .. .. .. ..$ meta      : NULL
#>   .. .. .. ..$ script    : NULL
#>   .. .. .. ..$ stylesheet: NULL
#>   .. .. .. ..$ head      : NULL
#>   .. .. .. ..$ attachment: NULL
#>   .. .. .. ..$ package   : NULL
#>   .. .. .. ..$ all_files : logi TRUE
#>   .. .. .. ..- attr(*, "class")= chr "html_dependency"
#>  - attr(*, "class")= chr "shiny.tag"
str(tq_html)
#> List of 3
#>  $ name    : chr "div"
#>  $ attribs : Named list()
#>  $ children:List of 3
#>   ..$ : chr "example"
#>   ..$ : chr "A"
#>   ..$ : chr "B"
#>  - attr(*, "class")= chr "shiny.tag"

# These should match
findDependencies(html)
#> [[1]]
#> List of 10
#>  $ name      : chr "barret"
#>  $ version   : chr "1"
#>  $ src       :List of 1
#>   ..$ file: chr "some/file.js"
#>  $ meta      : NULL
#>  $ script    : NULL
#>  $ stylesheet: NULL
#>  $ head      : NULL
#>  $ attachment: NULL
#>  $ package   : NULL
#>  $ all_files : logi TRUE
#>  - attr(*, "class")= chr "html_dependency"
findDependencies(tq_html)
#> NULL

Created on 2021-12-06 by the reprex package (v2.0.0)

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

Successfully merging a pull request may close this issue.

2 participants