Describe how a single data-table column renders. Pass a named list of these
as the columns argument of shad_data_table(), keyed by data-frame column
name; any column without a spec uses sensible type-based defaults.
Usage
shad_col(
header = NULL,
sortable = NULL,
filterable = NULL,
align = c("left", "center", "right"),
width = NULL,
visible = TRUE,
html = FALSE,
format = NULL,
cell = NULL
)Arguments
- header
Column header label.
NULLuses the data-frame column name.- sortable
Whether the column is sortable.
NULLinherits the table'ssortablemaster switch.- filterable
Whether the per-column filter (when enabled) applies here.
NULLdefaults toTRUE.- align
"left"(default),"center", or"right".- width
Optional CSS width for the column header.
- visible
Whether the column starts visible (column-visibility menu can toggle it).
- html
If
TRUE, the column's character values are treated as trusted, pre-rendered HTML rather than escaped text. Mutually exclusive withformat/cell.- format
A formatter from
shad_fmt_number(),shad_fmt_percent(),shad_fmt_date(), orshad_fmt_badge(). Mutually exclusive withcell.- cell
A function
function(value, row)returning an htmltools tag or character string, evaluated in R at render time (for embeddingshad_badge(),shad_button(), links, …). Mutually exclusive withformat.
See also
Other shadshiny data table:
shad_data_table(),
shad_data_table_server(),
shad_fmt,
update_shad_data_table()
Examples
shad_col("Amount", format = shad_fmt_number(prefix = "$"))
#> $header
#> [1] "Amount"
#>
#> $sortable
#> NULL
#>
#> $filterable
#> NULL
#>
#> $align
#> [1] "left"
#>
#> $width
#> NULL
#>
#> $visible
#> [1] TRUE
#>
#> $html
#> [1] FALSE
#>
#> $format
#> function (x)
#> {
#> num <- suppressWarnings(as.numeric(x))
#> disp <- ifelse(is.na(num), NA_character_, paste0(prefix,
#> formatC(num, format = "f", digits = digits, big.mark = big_mark),
#> suffix))
#> .cell_num(disp, num)
#> }
#> <bytecode: 0x5ffc4c7e7208>
#> <environment: 0x5ffc4c7e6398>
#> attr(,"class")
#> [1] "shad_fmt"
#>
#> $cell
#> NULL
#>
#> attr(,"class")
#> [1] "shad_col"
shad_col("Status", cell = function(v, row) shad_badge(v))
#> $header
#> [1] "Status"
#>
#> $sortable
#> NULL
#>
#> $filterable
#> NULL
#>
#> $align
#> [1] "left"
#>
#> $width
#> NULL
#>
#> $visible
#> [1] TRUE
#>
#> $html
#> [1] FALSE
#>
#> $format
#> NULL
#>
#> $cell
#> function (v, row)
#> shad_badge(v)
#> <environment: 0x5ffc4c7d7208>
#>
#> attr(,"class")
#> [1] "shad_col"