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

Allow additional args in result of create_custom_dependency() #28

Open
hypebright opened this issue Jan 25, 2024 · 0 comments
Open

Allow additional args in result of create_custom_dependency() #28

hypebright opened this issue Jan 25, 2024 · 0 comments

Comments

@hypebright
Copy link
Contributor

The resulting dependency functions of create_custom_dependency are not that convenient to work with if you want to add other HTML dependencies that are not in your package, like font awesome.

By allowing additional arguments, users can add dependencies (or other tags) to the tagList. The result of create_custom_dependency() could then look like this:

#' sportsswitch dependencies utils
#'
#' @description This function attaches sportsswitch dependencies to the given tag
#'
#' @param tag Element to attach the dependencies.
#' @param ... Additional arguments passed to \code{\link[htmltools]{tagList}}.
#'
#' @importFrom utils packageVersion
#' @importFrom htmltools tagList htmlDependency
#' @export
add_sportsswitch_deps <- function(tag, ...) {
 sportsswitch_deps <- htmlDependency(
  name = "sportsswitch",
  version = "0.1.0",
  src = c(file = "shinySportsKit-0.1.0"),
  script = "dist/sportsswitch.min.js",
  stylesheet = "dist/sportsswitch.min.css",
  package = "shinySportsKit",
 )
 tagList(tag, sportsswitch_deps, ...)
}

This allows users to add another dependency like font awesome like so:

add_sportsswitch_deps(
  tag,
  fontawesome::fa_html_dependency()
)

This is mainly handy for component based bundling, where some components make use of dependency X, and others don't.

Currently the alternative is to use two or more tagLists, which is fine, but just a bit lengthy:

c(
  add_sportsswitch_deps(
    tag
  ),
  tagList(fontawesome::fa_html_dependency())
)
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

1 participant