Tooltip module
mod_tooltip.RdA lightweight UI helper that wraps several tooltip/popover/modal back-ends behind a single, consistent interface. Drop it anywhere inside a UI or another module — no paired server function is required.
Arguments
- trigger
A
shiny.tag(or plain text) that the tooltip attaches to. Defaults to a smallbsicons::bs_icon("info-circle").- type
Back-end to use. One of
"bslib"(default),"shinyhelper","prompter", or"shinyalert".- contents
Character string or vector — the tooltip/popover/modal body. HTML is accepted for
"bslib". For"shinyhelper"a plain-text character vector is preferred — elements are joined with<br>byhelper(type = "inline"), so embedding HTML tags causes double-escaping. Ignored as plain text by"prompter". For"shinyalert"HTML is supported (rendered viahtml: true).- size
CSS font-size for the trigger wrapper span, e.g.
"0.85rem".NULL(default) leaves the font size unchanged. Note: this is purely a CSS property on the wrapper — it is distinct fromhelper_size(the shinyhelper modal size).- style
Additional inline CSS for the trigger wrapper, e.g.
"color:#6c757d".NULL(default) applies none.- helper_type
Content type forwarded to
shinyhelper::helper()as itstypeargument. One of"inline"(default) or"markdown". Ignored by all other back-ends.- helper_size
Modal size forwarded to
shinyhelper::helper()as itssizeargument. One of"s","m"(default), or"l". Ignored by all other back-ends. Kept separate fromsizeto avoid the two params colliding.- alert_type
Alert style forwarded to
shinyalert()as itstypeargument. One of"info"(default),"success","warning", or"error". Ignored by all other back-ends.- ...
Extra arguments forwarded directly to the underlying back-end function:
"bslib"→bslib::popover()(e.g.title,placement)"shinyhelper"→shinyhelper::helper()(e.g.title,colour,icon,buttonLabel,easyClose,fade)"prompter"→prompter::add_prompt()(e.g.position,rounded,bounce,arrow,animate)"shinyalert"→ stored asdata-sa-*attributes; recognised keys aretitleandconfirmButtonText
shinyalert usage in UI
type = "shinyalert" requires a delegated jQuery click handler injected
into the page. See vignette for more information:
I.e., in app_ui.R:
Examples
if (FALSE) { # \dontrun{
# bslib popover (click to open)
mod_tooltip(
type = "bslib",
contents = "A <b>bslib</b> popover with HTML.",
title = "More info"
)
# shinyhelper inline help modal
mod_tooltip(
trigger = shiny::tags$span("Sharpe Ratio"),
type = "shinyhelper",
contents = c("Sharpe Ratio", "Assumes a zero risk-free rate."),
helper_type = "inline",
helper_size = "m",
title = "Sharpe Ratio"
)
# prompter attribute-driven tooltip
mod_tooltip(
trigger = bsicons::bs_icon("info-circle"),
type = "prompter",
contents = "Number of trading days in the rolling window.",
position = "right"
)
# shinyalert modal on click (requires sa-handler to be present in UI)
mod_tooltip(
trigger = shiny::tags$span("What is ann. vol?"),
type = "shinyalert",
contents = "Annualised volatility = SD of daily log returns x sqrt(252).",
title = "Annualised Volatility",
alert_type = "info"
)
} # }