Defines functions rewriteTags isTag isTagList takeHeads

# Walk a tree of tag objects, rewriting objects according to func.
# preorder=TRUE means preorder tree traversal, that is, an object
# should be rewritten before its children.
rewriteTags <- function(ui, func, preorder) {
  if (preorder)
    ui <- func(ui)
  if (isTag(ui)) {
    ui$children[] <- lapply(ui$children, rewriteTags, func, preorder)
  } else if (isTagList(ui)) {
    ui[] <- lapply(ui, rewriteTags, func, preorder)
  if (!preorder)
    ui <- func(ui)

isTag <- function(x) {
  inherits(x, "shiny.tag")

isTagList <- function(x) {
  is.list(x) && (inherits(x, "shiny.tag.list") || identical(class(x), "list"))

# Given a tag object, extract out any children of tags$head
# and return them separate from the body.
takeHeads <- function(ui) {
  headItems <- list()
  result <- rewriteTags(ui, function(uiObj) {
    if (isTag(uiObj) && tolower(uiObj$name) == "head") {
      headItems <<- append(headItems, uiObj$children)
  }, FALSE)
  return(list(ui=result, head=headItems))

known_tags <- c(
names(known_tags) <- known_tags

tags <- lapply(known_tags, function(tagname) {
  function(...) {
    contents <- list(...)
    tag(tagname, contents)

#' Namespaced IDs for inputs/outputs
#' @param namespace The character vector to use for the namespace. 
#' This can have any length, though a single element is most common. 
#' Length 0 will cause the id to be returned without a namespace, and 
#' length 2 will be interpreted as multiple namespaces, in increasing 
#' order of specificity (i.e. starting with the top-level namespace).
#' @param id The id string to be namespaced (optional).
NS <- function (namespace, id = NULL) {
  if (length(namespace) == 0) 
    ns_prefix <- character(0)
  else ns_prefix <- paste(namespace, collapse = ns.sep)
  f <- function(id) {
    if (length(id) == 0) 
    if (length(ns_prefix) == 0) 
    paste(ns_prefix, id, sep = ns.sep)
  if (missing(id)) {
  else {

#' @rdname NS
#' @export
ns.sep <- "-"

Try the argonR package in your browser

Any scripts or data that you put into this service are public.

argonR documentation built on Dec. 1, 2019, 1:15 a.m.