Create 'lazily' rendered HTML tags (and/or htmlDependencies()
).
tagFunction(func)
a function with no arguments that returns HTML tags and/or dependencies.
When possible, use tagAddRenderHook()
to provide both a tag
structure and utilize a render function.
myDivDep <- tagFunction(function() {
if (isTRUE(getOption("useDep", TRUE))) {
htmlDependency(
name = "lazy-dependency",
version = "1.0", src = ""
)
}
})
myDiv <- attachDependencies(div(), myDivDep)
renderTags(myDiv)
#> $head
#>
#>
#> $singletons
#> character(0)
#>
#> $dependencies
#> $dependencies[[1]]
#> List of 10
#> $ name : chr "lazy-dependency"
#> $ version : chr "1.0"
#> $ src :List of 1
#> ..$ file: chr ""
#> $ meta : NULL
#> $ script : NULL
#> $ stylesheet: NULL
#> $ head : NULL
#> $ attachment: NULL
#> $ package : NULL
#> $ all_files : logi TRUE
#> - attr(*, "class")= chr "html_dependency"
#>
#>
#> $html
#> <div></div>
#>
withr::with_options(list(useDep = FALSE), renderTags(myDiv))
#> $head
#>
#>
#> $singletons
#> character(0)
#>
#> $dependencies
#> list()
#>
#> $html
#> <div></div>
#>