Package {shinyHierarchy}


Title: Hierarchical Input Component for Shiny
Version: 0.1.0
Description: Hierarchical slicer-style input for Shiny applications with multi-selection, tri-state checkboxes, search, cascading selection, and a structured selection value for analytics workflows.
License: MIT + file LICENSE
Encoding: UTF-8
Depends: R (≥ 4.1.0)
Imports: shiny, htmltools, jsonlite
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
Config/roxygen2/version: 8.1.0
NeedsCompilation: no
Packaged: 2026-09-22 19:07:52 UTC; luis.rodriguez
Author: Luis Rodriguez [aut, cre]
Maintainer: Luis Rodriguez <devmazter92@gmail.com>
Repository: CRAN
Date/Publication: 2026-10-02 10:10:09 UTC

shinyHierarchy: Hierarchical Input Component for Shiny

Description

Hierarchical slicer-style input for Shiny applications with multi-selection, tri-state checkboxes, search, cascading selection, and a structured selection value for analytics workflows.

Author(s)

Maintainer: Luis Rodriguez devmazter92@gmail.com

Authors:


Build a hierarchical tree from tabular data

Description

Converts a data frame and an ordered set of columns into a nested hierarchy suitable for the Shiny input component.

Usage

buildHierarchyTree(data, levels)

Arguments

data

A data frame containing the hierarchy columns.

levels

A character vector with column names, ordered from highest to lowest hierarchy level.

Value

A list representing the hierarchy tree.

Examples

data <- data.frame(
  year = c(2026, 2026, 2026),
  month = c("January", "January", "February"),
  day = c(1, 2, 1)
)
buildHierarchyTree(data, c("year", "month", "day"))

Hierarchical tree input for Shiny

Description

Creates a hierarchical slicer-style input similar to a Power BI date hierarchy. The input value is a structured object (schema version 1) with resolved, rollup, explicit, and summary fields.

Usage

hierarchyInput(
  inputId,
  label = NULL,
  data,
  levels,
  selected = NULL,
  expanded = NULL,
  placeholder = "Selección múltiple",
  display = c("inline", "dropdown"),
  search = FALSE,
  searchPlaceholder = "Buscar...",
  selectAll = TRUE,
  selectAllLabel = "Seleccionar todo",
  expand = c("first", "all", "none"),
  width = "100%",
  height = "360px"
)

Arguments

inputId

The input slot that will be used to access the value.

label

Optional label displayed above the component.

data

A data frame containing the hierarchy columns.

levels

Character vector with column names, ordered from highest to lowest hierarchy level.

selected

Optional character vector of node ids to select initially.

expanded

Optional character vector of node ids to expand initially.

placeholder

Text shown when nothing is selected.

display

Visual presentation: "inline" keeps the tree visible, while "dropdown" opens it in a floating panel.

search

Whether to show a search box above the tree.

searchPlaceholder

Placeholder for the search field.

selectAll

Whether to show the select-all row.

selectAllLabel

Label for the select-all control.

expand

Initial expansion mode: first level, all levels, or none.

width

CSS width of the component.

height

CSS max-height of the tree area.

Details

The value received from the browser is user-controlled and must not be used as an authorization mechanism. Applications that filter sensitive data must validate selected ids against the server-side hierarchy and permissions.

Value

A Shiny HTML object.


Extract path values at a given hierarchy level

Description

Extract path values at a given hierarchy level

Usage

hierarchyPath(value, level_name)

Arguments

value

Value returned by a hierarchy input (input$...).

level_name

Name of the hierarchy level column.

Value

A character vector of unique values at that level among resolved selections.


Extract resolved leaf selections from a hierarchy input value

Description

Extract resolved leaf selections from a hierarchy input value

Usage

hierarchyResolved(value)

Arguments

value

Value returned by a hierarchy input (input$...).

Value

A list of resolved node records, or an empty list.


Extract rollup selections from a hierarchy input value

Description

Extract rollup selections from a hierarchy input value

Usage

hierarchyRollup(value)

Arguments

value

Value returned by a hierarchy input (input$...).

Value

A list of rollup node records, or an empty list.


Update a hierarchical input from the server

Description

Update a hierarchical input from the server

Usage

updateHierarchyInput(
  session = shiny::getDefaultReactiveDomain(),
  inputId,
  data = NULL,
  levels = NULL,
  selected = NULL,
  expanded = NULL,
  clear = FALSE,
  open = NULL
)

Arguments

session

Shiny session object.

inputId

The input id to update.

data

Optional new data frame.

levels

Optional hierarchy column names (required if data is set).

selected

Optional vector of node ids to select (cascades to descendants).

expanded

Optional vector of node ids to expand.

clear

If TRUE, clears the current selection.

open

If TRUE or FALSE, opens or closes the dropdown panel.

Value

No useful return value, invisibly NULL.