tip_show() opens the tip of a tag, tip_hide() closes it, and tip_update() changes what the tip says, from a
Shiny server function. The tag is found by the id given to tip_on(), or, when tip_on() had none, by the tag's
own id. For a tip of a tip_table() give the table's id and the address of the tip: row alone is a row, row
and column a cell, and column alone a header cell. For a tip on a tag, leave both out.
Usage
tip_show(
id,
...,
row = NULL,
column = NULL,
session = shiny::getDefaultReactiveDomain()
)
tip_hide(
id,
...,
row = NULL,
column = NULL,
session = shiny::getDefaultReactiveDomain()
)
tip_update(
id,
text = NULL,
...,
template = NULL,
record = NULL,
placement = NULL,
row = NULL,
column = NULL,
session = shiny::getDefaultReactiveDomain()
)Arguments
- id
The tip's id: the
idgiven totip_on(), or, withroworcolumn, theidgiven totip_table(), without the module's namespace. One non-empty string with no whitespace and no:.- ...
Must be empty. It makes a misspelt argument an error.
- row, column
The address of a table's tip:
rowthe row's position in the data,columna data column's name or position. BothNULL(the default) for a tip on a tag.- session
The Shiny session; the default is the one the call runs in.
- text, template, record, placement
For
tip_update(): the new values, as intip_on().NULL(the default) leaves a value as it is andNAtakes it away;""clears thetext. Give at least one. For atemplatethat R has not seen in this process (it was defined in another session or process),recordsends every column, since R cannot know which ones the template names: choose the columns yourself.
Details
row is the position of the row in the data the table has now, counting from 1: after replaceData() or a redraw
with other data, row 3 is whatever is third. It is not a record's id, so do not keep it to find a record later.
column is the data column, by its name in the data frame (not the header's words) or its position among the data
columns, without the row-names column. A name is read from the table that tip_table() drew in this session, so the
table has to have been drawn: a name that is not a column of a table already drawn stops with an error that lists the
columns; a name given before the table's first draw is read when the call is sent, and if it is still not a column
then, the call warns (class hovercraft_warning_table) and sends nothing. A position needs no table. A column that
the widget hides has no tip. A row that is not on the table's current page has no element yet, in any paged table
(DT in client or server mode, reactable), so nothing happens until it is on the page.
A call reaches only a tag that is on the page and drawn at that moment; nothing is queued, and a tag in a hidden tab
opens nothing. On a page without Shiny (R Markdown, Quarto, a static page) the calls stop with an error. Every call
is sent when the flush that follows it is done, and asks for that flush, so tip_show() in the same observer as a
renderUI() that draws the tag reaches the new tag, and a call from a callback of later is sent too.
A tip opened by tip_show() stays open until tip_hide() closes it, or until the reader opens another tip, presses
Escape or clicks away. tip_hide() closes a hint, the tip that shows on hover or focus, and never a pin: when the
tip of this id is not the hint that is open (another tip's hint is, or this one is pinned or closed), it does
nothing. No server call pins a tip or closes a pin.
tip_update() rewrites the tag's tip attributes. It takes the values of tip_on() that change a tip (text,
template, record and placement) and changes only what is named: NULL leaves a value as it is, NA takes it
away, and for text, "" clears the words. template is the name of a template or a tip_template(), which is
sent with the call (not one that holds a tip_output(), which needs the tag's own tip_on()); text with
{{ field }} placeholders is filled from record, as in tip_on(). An open tip draws its new words, template or
record at once; a new placement is used the next time the tip opens. A record needs a template, or text with
placeholders, in the same call, so that only the columns it names are sent to the page; to change the template
alone, leave record out and the tag keeps the record it has. A template given without text also takes the
tag's plain text away, since plain text beats a template. text and template in
one call: the text beats the template, so the tip shows the words and the template is not used, and the words are
plain text, with their braces as written; to fill {{ field }} placeholders from record, give the words alone.
tip_update() leaves a style or marker alone, and it leaves the tag's aria-label as it is, so a button named
from its tip keeps the old name; give such a button its own aria-label. The new tip lasts until the tag is drawn
again, for example by renderUI().
On a control that has when_disabled, tip_update() changes the control's own tip, also while the control is
disabled. A disabled control still says only "Not available:" and its reason, in the new placement; the new text,
template and record show once the control is enabled.
Inside a module, give the id as the module's own ("save"); the call adds the module's namespace, as the update*()
functions of Shiny do. In the module's UI, give tip_on() the id as ns("save").
See also
Other tooltips:
tip_blocks,
tip_define(),
tip_marker(),
tip_more(),
tip_on(),
tip_output(),
tip_presets(),
tip_spec(),
tip_style(),
tip_table(),
tip_template(),
tip_theme(),
use_hovercraft()
Examples
if (interactive() && requireNamespace("shiny", quietly = TRUE)) {
ui <- shiny::fluidPage(
tip_on(shiny::actionButton("run", "Run"), "Runs the **check**", id = "run_tip"),
shiny::actionButton("show", "Show the tip"),
shiny::actionButton("hide", "Hide it"),
shiny::actionButton("change", "Change it")
)
server <- function(input, output, session) {
shiny::observeEvent(input$show, tip_show("run_tip"))
shiny::observeEvent(input$hide, tip_hide("run_tip"))
shiny::observeEvent(input$change, tip_update("run_tip", text = "Runs the **new check**"))
}
shiny::shinyApp(ui, server)
}