Display statistics.
Basic usage
To highlight a number or a group of numbers, such as statistical value, amount, and ranking, you can add elements such as icon and unit before and after the number and title. And use vueuse to add animated transitions to value.
The total counts up to its value, with VueUse’s
useTransition(), as upstream’s does: an
el$statistic() in a [vue_app()] whose setup()
moves the number, with [vueuse_dependency()].
el_row(
el_col(span = 6, el_statistic(title = "Daily active users", value = 268500)),
el_col(
span = 6,
el_statistic(
value = 138,
slots = list(
title = tags$div(
style = "display: inline-flex; align-items: center",
"Ratio of men to women ",
el_icon("Warning", size = "12px")
),
suffix = "/100"
)
)
),
el_col(
span = 6,
vue_app(
"stat_total",
el$statistic(title = "Total Transactions", `:value` = "outputValue"),
setup = JS(
"function() {",
" var source = Vue.ref(0);",
" var outputValue = VueUse.useTransition(source, { duration: 1500 });",
" source.value = 172000;",
" return { outputValue: outputValue };",
"}"
),
use = "shinyElement.plugin",
dependencies = vueuse_dependency()
)
),
el_col(
span = 6,
el_statistic(
title = "Feedback number",
value = 562,
slots = list(suffix = el_icon("ChatLineRound"))
)
)
)Countdown
Countdown component, support to add other components control countdown.
input$<id>_finish fires at zero. The second one’s
value is a store’s field, [v_model()]: Reset sets it again,
in the browser.
next_month <- as.POSIXct(
format(seq(Sys.Date(), by = "month", length.out = 2)[2], "%Y-%m-01")
)
col <- function(...) {
el_col(
xs = 24,
sm = 12,
md = 8,
style = "text-align: center; margin-bottom: 16px",
...
)
}
vue_store(
"vip",
state = list(
until = as.numeric(Sys.time() + 60 * 60 * 24 * 2 - 60 * 60) * 1000
)
)
el_row(
gutter = 16,
col(el_countdown(
"cd_grab",
title = "Start to grab",
value = Sys.time() + 60 * 60 * 7
)),
col(
el_countdown(
"cd_vip",
title = "Remaining VIP time",
format = "HH:mm:ss",
value = v_model("$vueStore.vip.until")
),
tags$div(
style = "margin-top: 8px",
el_button(
"cd_reset",
"Reset",
type = "primary",
on = list(
click = "$vueStore.vip.until = Date.now() + 1000 * 60 * 60 * 24 * 2"
)
)
)
),
col(
el_countdown(
"cd_month",
format = "DD [days] HH:mm:ss",
value = next_month,
slots = list(
title = tags$div(
style = "display: inline-flex; align-items: center",
el_icon("Calendar", size = 12, style = "margin-right: 4px"),
"Still to go until next month"
)
)
),
tags$div(style = "margin-top: 8px", format(next_month, "%Y-%m-%d"))
)
)Tip
In formatting it is suggested to be in the range of days
Card usage
Card usage display, can be freely combined
card <- function(title, value, delta, up) {
el_col(
span = 8,
tags$div(
style = paste(
"height: 100%; padding: 16px; border-radius: 4px; background: var(--el-bg-color-overlay)"
),
el_statistic(title = title, value = value),
tags$div(
style = "font-size: 12px; color: var(--el-text-color-regular); margin-top: 16px",
"than yesterday ",
tags$span(
style = sprintf(
"color: var(--el-color-%s)",
if (up) "success" else "error"
),
delta,
el_icon(if (up) "CaretTop" else "CaretBottom")
)
)
)
)
}
el_row(
gutter = 16,
card("Daily active users", 98500, "24%", TRUE),
card("Monthly Active Users", 693700, "12%", FALSE),
card("New transactions today", 72000, "16%", TRUE)
)API
Element Plus’s tables, and beside each entry where it is in R.
Statistic Attributes
| Element | In R | Description | Type | Accepted | Default |
|---|---|---|---|---|---|
value |
el_statistic(value =) |
Numerical content | 1 | 0 | |
decimal-separator |
el_statistic(decimal_separator =) |
Setting the decimal point | 2 | . | |
formatter |
el_statistic(formatter =) |
Custom numerical presentation |
3(value: number) => string \\| number
|
— | |
group-separator |
el_statistic(group_separator =) |
Sets the thousandth identifier | 4 | , | |
precision |
el_statistic(precision =) |
numerical precision | 5 | 0 | |
prefix |
el_statistic(prefix =) |
Sets the prefix of a number | 6 | — | |
suffix |
el_statistic(suffix =) |
Sets the suffix of a number | 7 | — | |
title |
el_statistic(title =) |
Numeric titles | 8 | — | |
value-style |
el_statistic(value_style =) |
Styles numeric values |
9 /
10CSSProperties \\| CSSProperties[] \\| string[]
|
— |
Statistic Slots
| Element | In R | Description |
|---|---|---|
prefix |
slots = list(prefix = ) |
Numeric prefix |
suffix |
slots = list(suffix = ) |
Suffixes for numeric values |
title |
slots = list(title = ) |
Numeric titles |
Countdown Attributes
| Element | In R | Description | Type | Accepted | Default |
|---|---|---|---|---|---|
value |
el_statistic(value =) |
target time | 11 / 12 | — | |
format |
el_countdown(format =) |
Formatting the countdown display | 13 | HH:mm:ss | |
prefix |
el_statistic(prefix =) |
Sets the prefix of a countdown | 14 | — | |
suffix |
el_statistic(suffix =) |
Sets the suffix of a countdown | 15 | — | |
title |
el_statistic(title =) |
countdown titles | 16 | — | |
value-style |
el_statistic(value_style =) |
Styles countdown values |
17
/ 18CSSProperties \\| CSSProperties[] \\| string[]
|
— |