| Type: | Package |
| Title: | Collapsible 'HTML' Tables from Hierarchical Data |
| Version: | 0.1.0 |
| Description: | Creates collapsible, expandable 'HTML' tables from hierarchical data. Supports data frame input with multi-level grouping, custom column formatters, bottom-up rollup aggregation, and CSS-variable-based theming. Works in 'Shiny' applications, R Markdown, 'Quarto', and the 'RStudio' Viewer. |
| License: | GPL (≥ 3) |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Imports: | htmltools (≥ 0.5.0) |
| Suggests: | shiny (≥ 1.7.0), testthat (≥ 3.0.0) |
| NeedsCompilation: | no |
| Packaged: | 2026-04-24 14:18:35 UTC; underwood_derek |
| Author: | Derek Underwood [aut, cre] |
| Maintainer: | Derek Underwood <dereku@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-04-28 19:00:10 UTC |
Define a table column
Description
Define a table column
Usage
col_def(
key,
header = NULL,
format = function(x) base::format(x),
color = NULL,
rollup = "sum",
width = NULL
)
Arguments
key |
Character. The value key — the column name in your data frame (or
the name used in each node's |
header |
Character. Column header text. Defaults to a title-cased
version of |
format |
Function |
color |
Function |
rollup |
How parent rows are aggregated. Either a shortcut string
( |
width |
CSS width string (e.g. |
Value
A named list describing the column.
Convert a flat data frame into a nested node tree
Description
Convert a flat data frame into a nested node tree
Usage
df_to_tree(
df,
name_col,
value_cols,
group_col = NULL,
total = NULL,
node_values = list()
)
Arguments
df |
A data frame. |
name_col |
Column name to use as the node label (leaf rows). |
value_cols |
Character vector of value column names. |
group_col |
Character vector of grouping columns, outermost first.
Each element adds one nesting level. |
total |
Optional string. When non- |
node_values |
Optional named list of pre-supplied values for group (and total) nodes. Each name is a node label; each value is a named list of column values that should be displayed as-is rather than rolled up from children. Useful when aggregated figures (e.g. time-weighted returns) are already known and differ from a simple weighted average of the leaves. Example — supply a pre-computed return for the "Technology" sector and the "Mag 7" grand total: node_values = list( "Technology" = list(ytd_return = 2.5), "Mag 7" = list(ytd_return = 4.1) ) Any column not listed for a node still falls back to rollup from children. |
Value
A list of node() objects suitable for passing to nestable().
Currency format function factory
Description
Returns a formatting function for use as format_fn in col_def().
Usage
fmt_currency(prefix = "$", suffix = "", digits = 2L, big_mark = ",")
Arguments
prefix |
Character prepended before the number. Default |
suffix |
Character appended after the number. Default |
digits |
Integer decimal places. Default |
big_mark |
Thousands separator. Default |
Value
A function function(x) -> character.
Percentage format function factory
Description
Returns a formatting function for use as format_fn in col_def().
Usage
fmt_percent(digits = 2L, plus = TRUE)
Arguments
digits |
Integer decimal places. Default |
plus |
Logical. Prefix non-negative values with |
Value
A function function(x) -> character.
Create a nestable collapsible HTML table
Description
Create a nestable collapsible HTML table
Usage
nestable(
data_root,
columns,
theme = nestable_theme(),
name_col = "name",
name_header = NULL,
name_col_width = NULL,
uid = new_widget_uid()
)
Arguments
data_root |
A list of top-level |
columns |
Column specification. Three forms are accepted:
|
theme |
A theme list from |
name_col |
Character. The node label key — the |
name_header |
Character. Header label for the first (name/label) column.
|
name_col_width |
CSS width string (e.g. |
uid |
Character. Widget UID prefix for HTML element |
Value
An htmltools::browsable() tagList. Renders inline in R Markdown,
Quarto, and the RStudio Viewer; use inside shiny::renderUI() or
renderNestable() in Shiny apps.
Shiny UI output for a nestable table
Description
Use with renderNestable() in the server. These are thin wrappers over
shiny::uiOutput() and shiny::renderUI() — no htmlwidgets dependency
is required.
Usage
nestableOutput(outputId, ...)
renderNestable(expr, env = parent.frame(), quoted = FALSE)
Arguments
outputId |
The output variable name. |
... |
Additional arguments passed to |
expr |
An expression returning a |
env |
The environment in which to evaluate |
quoted |
Logical. Is |
Value
A Shiny UI element.
A Shiny render function.
Create a nestable theme
Description
Every argument maps to a CSS custom property (--ntbl-*) set inline on
the widget's wrapper <div>, so multiple instances with different themes
can coexist on the same page without conflict.
Usage
nestable_theme(
title = "",
font_family = "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif",
font_size = "14px",
table_bg = "#ffffff",
table_shadow = "0 1px 4px rgba(0,0,0,.12)",
table_radius = "6px",
table_max_w = "680px",
header_bg = "#37474f",
header_color = "#ffffff",
row_border = "#eceff1",
row_hover_bg = "#f9fbe7",
parent_weight = "600",
toggle_color = "#546e7a",
indent_px = 20L,
zoom = "normal"
)
Arguments
title |
Character. Title shown above the table. Default |
font_family |
CSS font-family string. |
font_size |
CSS font-size string. Default |
table_bg |
Table background colour. Default |
table_shadow |
CSS box-shadow for the table. |
table_radius |
CSS border-radius. Default |
table_max_w |
CSS max-width. Default |
header_bg |
Header row background. Default |
header_color |
Header row text colour. Default |
row_border |
Row separator colour. Default |
row_hover_bg |
Row hover background. Default |
parent_weight |
CSS font-weight for parent rows. Default |
toggle_color |
Colour of the expand/collapse arrow. Default |
indent_px |
Integer pixels of indentation per nesting level. Default |
zoom |
CSS zoom level applied to the entire widget. Accepts any valid
CSS |
Value
A named list of theme values.
Define a tree node
Description
Define a tree node
Usage
node(name, ..., .values = list())
Arguments
name |
Display label shown in the Name column. |
... |
Child |
.values |
Named list of column values. For leaf nodes supply all values here. For parent nodes any value supplied here overrides the computed rollup for that column; omitted columns are still computed from children. |
Value
A named list with elements name, values, and children.
Convert data frame rows into leaf nodes
Description
Convert data frame rows into leaf nodes
Usage
rows_to_nodes(df, name_col, value_cols)
Arguments
df |
A data frame. |
name_col |
Column name to use as the node label. |
value_cols |
Character vector of column names to carry as |
Value
A list of node() objects.
Weighted-average rollup function factory
Description
Returns a rollup function for use as rollup_fn in col_def(). Computes
the weighted average of vals using another key's values as weights.
Usage
weighted_rollup(weight_key)
Arguments
weight_key |
Character. The value key to use as weights (e.g.
|
Value
A function function(vals, child_values) -> numeric.