| Title: | Tooltips for 'Shiny' and 'bslib' Pages |
|---|---|
| Description: | Puts a tip on any 'HTML' tag in a 'Shiny' app or a 'bslib' page. The tip shows when the pointer rests on the tag or keyboard focus arrives, and holds plain text or a named template filled in from the values of one item, such as a row of a table. Tips follow the page's light and dark mode and can be themed, with a contrast check. They are drawn by a small 'JavaScript' file that ships with the package. |
| Authors: | Harsh Verma [aut, cre, cph] (Copyright holder of the package and of the bundled tip engine) |
| Maintainer: | Harsh Verma <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.90 |
| Built: | 2026-11-27 17:53:12 UTC |
| Source: | https://github.com/insightsurge/hovercraft |
Opens hovercraft book, a Shiny app that shows every feature of the package on one page, in six parts: getting
started, content, interaction, look, tips from Shiny, and tables. Each section is one feature: a live figure to rest
the pointer on, a sentence of choices that change it, the R code that makes what you see (ready to copy), a short
list of what to test, and the Shiny inputs the page sends. The code a section shows is the code that draws its
figure. The index has a search box, and the checklist (the key C) shows one test step at a time and ticks a step
when the server receives the input that proves it.
hovercraft_book(section = NULL, ..., checklist = FALSE, run = TRUE)hovercraft_book(section = NULL, ..., checklist = FALSE, run = TRUE)
section |
The section to open on, or |
... |
Must be empty. It makes a misspelt argument an error. |
checklist |
|
run |
|
The book needs the suggested packages shiny and bslib; its table sections also need DT or reactable. Its
files are in system.file("book", package = "hovercraft").
Unlike the other functions of the package, its name does not start with tip_: it opens the package's own book,
not a tip.
With run = FALSE, the app, a shiny.appobj. With run = TRUE, what shiny::runApp() returns when the
app stops.
app <- hovercraft_book(section = "pins", run = FALSE) inherits(app, "shiny.appobj")app <- hovercraft_book(section = "pins", run = FALSE) inherits(app, "shiny.appobj")
The parts a template is made of.
tip_title() is the first line, tip_text() a paragraph of markdown,
tip_badge() a short label, tip_fields() a list of label and value pairs, and tip_code() a piece of code shown
as text. Text and values may hold placeholders, {{ field }} or {{ field | number:2 }}, filled from the record of
the item the tip belongs to. A placeholder names one field, matched exactly (dots and spaces allowed), and takes one
filter at most: number (digits after the point, rounded as R does) or percent (the value times 100, then digits,
then a percent sign). A value that is missing or blank shows a dash. There is no way to write a literal {{ yet.
tip_title(text) tip_text(text) tip_badge(text, status = NULL) tip_fields(...) tip_code(field, language = NULL, copy = FALSE)tip_title(text) tip_text(text) tip_badge(text, status = NULL) tip_fields(...) tip_code(field, language = NULL, copy = FALSE)
text |
One string, with placeholders if you like. In |
status |
What the badge says about its item, or |
... |
Named strings for |
field |
One string: the name of the record field that holds the code. The code is shown as text, never run, and never filled in by placeholders. |
language |
One string naming the code's language, or |
copy |
|
A block, to give to tip_template().
Other tooltips:
tip_define(),
tip_marker(),
tip_more(),
tip_on(),
tip_output(),
tip_presets(),
tip_server,
tip_spec(),
tip_style(),
tip_table(),
tip_template(),
tip_theme(),
use_hovercraft()
tip_title("{{ label }}") tip_text("**{{ differences | number:0 }}** differences") tip_badge("{{ status }}", status = "warning") tip_fields(Records = "{{ records | number:0 }}", Files = "{{ files }}") tip_code("sql", language = "sql")tip_title("{{ label }}") tip_text("**{{ differences | number:0 }}** differences") tip_badge("{{ status }}", status = "warning") tip_fields(Records = "{{ records | number:0 }}", Files = "{{ files }}") tip_code("sql", language = "sql")
Puts named templates on the page, so a tag can use one with
tip_on(tag, template = "name"). Put the result in the page's UI, once. Names are page-wide. A name is lower-case letters, digits and _,
starting with a letter; inside a Shiny module, prefix it with ns() (for example tip_define(!!ns("row") := tip_template(...))) so two copies of the module keep their own templates without overwriting each other. Defining
the same name again replaces the earlier template under it, with a warning when the blocks differ.
tip_define(...)tip_define(...)
... |
Templates, each with a name: |
The templates are also kept in R, so that tip_on() can check a record against them. Defined in a Shiny session (in
renderUI() or a module's server), they belong to that session: two sessions of one app may define one name with
different fields and each is checked against its own. Defined where the UI is built, they belong to the process and
every session is checked against them; a session may define the name again for itself, without a warning. A
renderUI() that is cached with bindCache() does not run again for the next session, so a template it defines is
known in R only to the session that ran it: define a template that sessions share where the UI is built.
Tags to put in the page's UI.
Other tooltips:
tip_blocks,
tip_marker(),
tip_more(),
tip_on(),
tip_output(),
tip_presets(),
tip_server,
tip_spec(),
tip_style(),
tip_table(),
tip_template(),
tip_theme(),
use_hovercraft()
tip_define( diff = tip_template( tip_title("{{ label }}"), tip_text("{{ differences | number:0 }} differences") ) )tip_define( diff = tip_template( tip_title("{{ label }}"), tip_text("{{ differences | number:0 }} differences") ) )
Describes the visible cue on a tipped tag, to give as
marker = to tip_on(), tip_table() or tip_spec(). For
the common cases marker = "underline", "icon" or "corner" is enough; use tip_marker() to choose the line of
an underline or to give your own icon.
tip_marker(type, ..., line = NULL, icon = NULL)tip_marker(type, ..., line = NULL, icon = NULL)
type |
The kind of marker: |
... |
Must be empty. It makes a misspelt argument an error. |
line |
Only for |
icon |
Only for |
A hovercraft_marker object, to give as marker = to tip_on(), tip_table() or tip_spec(). Its
fields are internal; pass the object on.
"underline" draws a line under the tag's words. It takes no room, so nothing moves. The line follows the tip
preset in use (see tip_style()): dotted for "none", "sober" and "dense", dashed for "modern" and
"editorial", and a long gentle wave for "lively". Choose one with line.
"icon" adds a small icon after the words: a circle with an i, or the icon you give. It takes a little room.
"corner" draws a small triangle in the top corner of the tag, as a spreadsheet does for a note. It takes no room
and suits a table cell or a card; on a single word it can look like a stray mark, so prefer "underline" there.
"none" draws nothing. It is what a tag has when marker is left out.
A marker is drawn in the tag's own text colour, so it keeps its contrast in light and dark. The pointer over a marked
tag is the help cursor, unless the tip can be pinned (it is then a hand), or the tag is a button or a link, which
keep their own. A tag that takes more than words, such as the div Shiny puts around an input, is marked
as a whole: put the marker on the label tag, or on the words, when that is what you mean.
A marked tag is highlighted while its tip shows, so a reader sees which marker the tip belongs to: a soft grey tint
on the words of an underline and on the tag of an icon or a corner (a table cell, a label), and a glow round a
bslib::value_box(), which has a background of its own. It goes when the tip closes. There is no argument for it,
and a tag with no marker is not highlighted. It follows the tip engine's open mark on the tag, for a tip that shows
on hover or focus and for one that is pinned.
For an underline, the words of a block tag (a td, a p, a div and so on) are put in a span inside the tag, so
that the line goes under the words and not across the whole cell or paragraph. In a bslib::value_box() the title
is marked. Tags inside the block that are not words are left as they are. A block that holds no words of its own,
such as a div of other tags, has nothing to underline and stops with an error: put the marker on the tag that holds
the words, or use "corner" or "icon".
Other tooltips:
tip_blocks,
tip_define(),
tip_more(),
tip_on(),
tip_output(),
tip_presets(),
tip_server,
tip_spec(),
tip_style(),
tip_table(),
tip_template(),
tip_theme(),
use_hovercraft()
tip_marker("underline") tip_marker("underline", line = "wavy") tip_marker("icon", icon = htmltools::tags$span("?")) tip_on( htmltools::tags$span("Baseline", tabindex = "0"), "The first **screening** value", marker = tip_marker("underline", line = "dashed") )tip_marker("underline") tip_marker("underline", line = "wavy") tip_marker("icon", icon = htmltools::tags$span("?")) tip_on( htmltools::tags$span("Baseline", tabindex = "0"), "The first **screening** value", marker = tip_marker("underline", line = "dashed") )
Wraps the words of a tip's long form with the moment it shows, to give as
more to tip_on() or tip_spec(). With
no tip_more(), more = "words" is the same as more = tip_more("words"): the tip is short, and a "More" button
in it opens the long form.
tip_more( content, ..., on = NULL, label = NULL, pin = FALSE, as = NULL, where = NULL )tip_more( content, ..., on = NULL, label = NULL, pin = FALSE, as = NULL, where = NULL )
content |
The words of the long form (markdown, with |
... |
Must be empty. It makes a misspelt argument an error. |
on |
When the long form shows: |
label |
The words of the buttons, only with |
pin |
|
as |
How the control looks: |
where |
Which side of the bottom of the tip the control sits on: |
With on = "button" (the default) a "More" button at the bottom of the short tip opens the long form in the same
tip, and a "Less" button closes it again. It does not pin (unless pin = TRUE, below), and needs no tip pin and
no id. The tip is short again the next time it opens. A pinned tip gets the same buttons. The M key opens and
closes the long form while the keyboard focus is on the tagged item or the pointer rests on it, except while the
focus is in a text field, where a letter is a letter. When the focus is on one item and the pointer rests on
another, the key acts on the item under the pointer, the tip the reader sees, not on one around it; a pinned tip
that holds the focus keeps the key. A tip that a tap or tip_show() opened does not take the key from the pointer.
It is a letter key that works from a hover, so a page switches it off for every reader with use_hovercraft(keys = c(more = FALSE)); there is no switch for one reader. A tag with a long form announces the key as
aria-keyshortcuts. The tip stays open and on its side when it grows or shrinks, grows away from its item and
scrolls when there is no more room, instead of flipping to the other side; that is the engine's own behaviour
(0.58.0).
as and where choose the look and the place of the control that opens the long form (only with on = "button").
as = "button" (the default) is the small button in the bottom corner of the tip, at its end; as = "link" is an
italic, underlined text link at the bottom of the tip, at its start. where says the side, "end" or "start",
and follows the reading direction, so the end is the right in English and the left in Arabic. Both are the same
control to a keyboard and a screen reader: the link is a real <button> styled as a link, which says "button" and
"expanded" or "collapsed" to a screen reader, takes Enter and Space, and does not navigate; an <a> would need
role = "button" and its own key handling to do the same. It is a tab stop in a pinned tip, M and
aria-keyshortcuts work as for the button, and the words are still the ones of label and labels.
With on = "click" a click on the tagged item opens and closes the long form, and the tip has no button. The item
should take keyboard focus (tabindex = "0" on a <span> or <div>), because the M key is the keyboard route:
it does the same, and the item announces it as aria-keyshortcuts. The long form is announced to a screen reader
when it opens; the item gets no aria-expanded and no role, since a click on a plain tag is not a control. The
tip must be open: a click that opens the tip (a first tap on a touch screen) only opens it, short, and the next
click opens or closes the long form (on a touch screen the engine closes the tip on a second tap, so use the
default button there). The click never pins, so pin = "click" with it is an error. A control, or a tag that
holds one (a button, an input, a link, a label ...), is refused, because a click on it has its own job, and so is
a table: a click on a row selects it. Use the default button there.
With pin = TRUE the "More" button, and the M key, also pin the tip, so the long form stays; "Less" then only
closes the long form and the tip stays pinned. It needs a tip that can pin, the same as on = "pin". Today's
default, pin = FALSE, never pins: a pinned tip stays pinned when it opens its long form.
With on = "hover" the long form shows at once, with the short one. With on = "pin" it shows when the tip is
pinned, so the tip must be able to pin: tip_on(pin = TRUE) with an id, or a row of tip_table() with
tip_spec(pin = TRUE); without a pin it is an error.
A tip that expands sends no Shiny input. A pinned tip drawn again, such as one that opens its long form, sends
input$<id>_pin with state = "updated"; the values of state may grow in a later version, so an app should
not assume it knows them all.
An object of class hovercraft_more, to give as more to tip_on() or tip_spec().
Other tooltips:
tip_blocks,
tip_define(),
tip_marker(),
tip_on(),
tip_output(),
tip_presets(),
tip_server,
tip_spec(),
tip_style(),
tip_table(),
tip_template(),
tip_theme(),
use_hovercraft()
tip_on( htmltools::tags$button("Run"), "Runs the checks.", more = tip_more("Takes about a minute on the full data.") ) # A click on the item opens the long form, and the More button pins the tip tip_on( htmltools::tags$span("Run", tabindex = "0"), "Runs the checks.", more = tip_more("Takes about a minute.", on = "click") ) tip_on( htmltools::tags$button("Run", id = "run"), "Runs the checks.", id = "run_tip", pin = TRUE, more = tip_more("Takes about a minute.", pin = TRUE) ) # A text link at the start of the bottom of the tip, instead of the button tip_on( htmltools::tags$button("Run"), "Runs the checks.", more = tip_more("Takes about a minute.", as = "link") ) # The long form shows with the short one, and the buttons say other words tip_on( htmltools::tags$button("Run"), "Runs the checks.", more = tip_more("Takes about a minute.", on = "hover") ) tip_on( htmltools::tags$button("Run"), "Runs the checks.", more = tip_more("Takes about a minute.", label = c(more = "Details", less = "Fewer details")) )tip_on( htmltools::tags$button("Run"), "Runs the checks.", more = tip_more("Takes about a minute on the full data.") ) # A click on the item opens the long form, and the More button pins the tip tip_on( htmltools::tags$span("Run", tabindex = "0"), "Runs the checks.", more = tip_more("Takes about a minute.", on = "click") ) tip_on( htmltools::tags$button("Run", id = "run"), "Runs the checks.", id = "run_tip", pin = TRUE, more = tip_more("Takes about a minute.", pin = TRUE) ) # A text link at the start of the bottom of the tip, instead of the button tip_on( htmltools::tags$button("Run"), "Runs the checks.", more = tip_more("Takes about a minute.", as = "link") ) # The long form shows with the short one, and the buttons say other words tip_on( htmltools::tags$button("Run"), "Runs the checks.", more = tip_more("Takes about a minute.", on = "hover") ) tip_on( htmltools::tags$button("Run"), "Runs the checks.", more = tip_more("Takes about a minute.", label = c(more = "Details", less = "Fewer details")) )
Gives one HTML tag a tip that shows after the pointer rests on it, or keyboard focus arrives, and hides when either
leaves. The tip is plain text, or drawn from a named template (
tip_define()) filled in from a record: the values of
one item, such as a row of a table. The engine's script and CSS are attached to the tag, so it works in a bslib page,
in a plain Shiny page and in output made later with renderUI(). A tag inside bslib::tooltip() or
bslib::popover(), or with data-bs-toggle, keeps the tip that bslib draws and this one is left off.
tip_on( tag, text = NULL, ..., template = NULL, record = NULL, style = NULL, placement = NULL, marker = NULL, id = NULL, events = NULL, when_disabled = NULL, more = NULL, pin = NULL, labels = NULL )tip_on( tag, text = NULL, ..., template = NULL, record = NULL, style = NULL, placement = NULL, marker = NULL, id = NULL, events = NULL, when_disabled = NULL, more = NULL, pin = NULL, labels = NULL )
tag |
|
text |
|
... |
Must be empty. It makes a misspelt argument an error. |
template |
|
record |
|
style |
|
placement |
|
marker |
|
id |
|
events |
|
when_disabled |
A disabled control takes no keyboard focus and, under Bootstrap 5, no pointer, so The wrapper takes the control's place in a layout: a width, a share of a flex row and a side written in its
|
more |
|
pin |
The pin button is drawn over the corner of the tip as a separate element, so a screen reader still gets a tip
that it only reads; the first block of the tip keeps room for it, so a one-sentence tip has the button at the
end of its line. The pin key is |
labels |
|
A tip shows on keyboard focus as well as on a pointer, so a tag that cannot take focus (a table row, a div) gives a
keyboard user no way to the tip. tip_on() looks at the tag and at everything inside it, so the div that Shiny
puts around an input is fine: the input takes focus. It warns once about a tag with nothing focusable in it, and
never adds a tabindex itself, because a table of 3,000 rows would become 3,000 Tab stops: give the tags worth a
stop tabindex = "0", or put the tip on a button or a link.
A button with no visible words, such as one that holds only an icon, has no name for a screen reader. When it also
has no aria-label or aria-labelledby of its own, and the tip is plain text, tip_on() gives it an
aria-label made from the text, with the markdown marks taken out. A tip drawn from a template gives no label,
because its words depend on the record: set aria-label yourself. The engine reads the tip once: when a tag's
name, from aria-label, aria-labelledby or its own words, is the same as the tip's words, the tip is not also
given to a screen reader as a description.
If both text and template are given, the text is shown for this tag. A template whose name has been defined in
this session is checked against the record here: a field it names that the record does not hold is an error. A
name that has not been defined is left to the page, which says so once in the browser's console.
A second tip_on() on a tag that already has a tip replaces the old tip whole: its words, look, id, events,
pin and when_disabled all go, and the new call's arguments are the tip. When the old tip had an id, events
or a pin and the new call gives none of them, it warns once, with the class hovercraft_warning_retip, so a wrapper
that tips a tag again on purpose can silence it with suppressWarnings(classes = ).
A tag that already has a title attribute keeps it, and the browser then shows its own tooltip beside the tip.
tip_on() warns once, with the class hovercraft_warning_title, and says to remove the title; it does not
remove it itself, because on an icon it may be the only name.
The tag, with the tip's attributes and the engine's dependency added; with a marker, its attributes,
and the marker's own dependency; with when_disabled, inside a wrapper that holds the reason.
tag, text, template, record, placement, id, pin (one pinned tip at a time, with its pin button and
the P key), more as words or a template (a "More" button opens the long form in the same tip) and a style that
is a preset name are r lifecycle::badge("stable"): their names, values and defaults do not change in 0.1.x. What
the long form's button looks like and the keys beyond the pin's are not part of that promise: the look and place
of the "More" button, the M key and the keys argument of use_hovercraft() are r lifecycle::badge("experimental"), like events and the fields of the inputs it turns on, when_disabled,
marker, a style that is a tip_style(), a tip_theme() or a bslib theme, a tip_more(), and keeping more
than one pin (max_pins of use_hovercraft()). They may change.
A tag inside bslib::tooltip() or bslib::popover(), or with data-bs-toggle, keeps the tip that bslib draws.
A pin closes (reason "gone") when its item is removed, or hidden by a tab, a conditional panel or a sidebar, and
it does not come back with the item. A pin whose item only scrolls out of view is hidden and returns when the item
does.
tip_on() costs about a millisecond of R time for each tag, and the page's script some time on every change of
the page: for a long table, page it.
Reconnecting an app (allowReconnect) is untested.
Other tooltips:
tip_blocks,
tip_define(),
tip_marker(),
tip_more(),
tip_output(),
tip_presets(),
tip_server,
tip_spec(),
tip_style(),
tip_table(),
tip_template(),
tip_theme(),
use_hovercraft()
tip_on(htmltools::tags$button("Run"), "Runs the **check**") # The reason a control is switched off tip_on( htmltools::tags$button("Run", disabled = NA), "Runs the **check**", when_disabled = "Pick a dataset first" ) # A tip that a reader can pin, by the button in its corner or by the P key tip_on( htmltools::tags$button("Run", id = "run"), "Runs the **check**", id = "run_tip", pin = TRUE, events = c("hint", "pin") ) # A short tip with a "More" button that opens the long form in the same tip tip_on( htmltools::tags$button("Run"), "Runs the **check**", more = "Checks every column and prints a summary." ) # The long form shows with the short one tip_on( htmltools::tags$button("Run"), "Runs the **check**", more = tip_more("Checks every column and prints a summary.", on = "hover") ) # A look for this tag only tip_on(htmltools::tags$button("Run"), "Runs the **check**", style = "sober") tip_on( htmltools::tags$button("Run"), "Runs the **check**", style = tip_theme(light = list(bg = "#1b3a6b", text = "#ffffff")) ) # A visible cue that a word holds a tip tip_on( htmltools::tags$span("Baseline", tabindex = "0"), "The first **screening** value", marker = "underline" ) tip_define(diff = tip_template( tip_title("{{ label }}"), tip_text("{{ differences | number:0 }} differences") )) rows <- data.frame(label = c("ADAE", "ADSL"), differences = c(3, 0)) lapply(seq_len(nrow(rows)), function(i) { tip_on( htmltools::tags$tr(htmltools::tags$td(rows$label[[i]]), tabindex = "0"), template = "diff", record = rows[i, ] ) }) # The built-in words of the tip, with other words, for this tip tip_on( htmltools::tags$button("Run"), "Runs the **check**", pin = TRUE, id = "run", labels = c(close = "Dismiss") ) # An icon-only button is named from its tip tip_on(htmltools::tags$button(htmltools::tags$i(class = "icon-gear")), "Open the **settings**")tip_on(htmltools::tags$button("Run"), "Runs the **check**") # The reason a control is switched off tip_on( htmltools::tags$button("Run", disabled = NA), "Runs the **check**", when_disabled = "Pick a dataset first" ) # A tip that a reader can pin, by the button in its corner or by the P key tip_on( htmltools::tags$button("Run", id = "run"), "Runs the **check**", id = "run_tip", pin = TRUE, events = c("hint", "pin") ) # A short tip with a "More" button that opens the long form in the same tip tip_on( htmltools::tags$button("Run"), "Runs the **check**", more = "Checks every column and prints a summary." ) # The long form shows with the short one tip_on( htmltools::tags$button("Run"), "Runs the **check**", more = tip_more("Checks every column and prints a summary.", on = "hover") ) # A look for this tag only tip_on(htmltools::tags$button("Run"), "Runs the **check**", style = "sober") tip_on( htmltools::tags$button("Run"), "Runs the **check**", style = tip_theme(light = list(bg = "#1b3a6b", text = "#ffffff")) ) # A visible cue that a word holds a tip tip_on( htmltools::tags$span("Baseline", tabindex = "0"), "The first **screening** value", marker = "underline" ) tip_define(diff = tip_template( tip_title("{{ label }}"), tip_text("{{ differences | number:0 }} differences") )) rows <- data.frame(label = c("ADAE", "ADSL"), differences = c(3, 0)) lapply(seq_len(nrow(rows)), function(i) { tip_on( htmltools::tags$tr(htmltools::tags$td(rows$label[[i]]), tabindex = "0"), template = "diff", record = rows[i, ] ) }) # The built-in words of the tip, with other words, for this tip tip_on( htmltools::tags$button("Run"), "Runs the **check**", pin = TRUE, id = "run", labels = c(close = "Dismiss") ) # An icon-only button is named from its tip tip_on(htmltools::tags$button(htmltools::tags$i(class = "icon-gear")), "Open the **settings**")
Puts any Shiny output — a plot, a
DT or reactable table, a gt table, a chart or uiOutput() — inside a
tip_template(). Give output as the Shiny output id (with ns() inside a module, such as ns("detail_plot")),
or as the output tag itself (such as shiny::plotOutput(ns("detail_plot")) or one wrapped in a loader like
shinycssloaders::withSpinner()). It needs Shiny: on a page without a server (R Markdown, Quarto, a static page)
the output stays empty.
tip_output(output, keep_alive = TRUE)tip_output(output, keep_alive = TRUE)
output |
The Shiny id of the output (one non-empty string with no whitespace, so |
keep_alive |
|
When output is given as an id string, place the matching *Output() tag in your UI (plain or wrapped in a loader
such as shinycssloaders); hovercraft parks it out of sight until a tip opens and moves it
into whichever item's tip is open. When output is given as an output tag, tip_define() places it in the hidden
holder for you together with its HTML dependencies.
With keep_alive = TRUE (the default), closing the tip parks the bound output in a hidden holder instead of
destroying it, so reopening the tip shows it at once without recomputing unless its reactive inputs changed. When a
parked output is shown again, hovercraft refreshes its visibility and size state so suspended outputs update.
With keep_alive = FALSE, closing the tip unbinds and removes the output from the page, and the next open builds it
again.
While the output computes (including async renders), hovercraft shows a plain loading placeholder unless the output
already uses an external loader. shinycssloaders is tested; waiter and bones are expected to work but are
untested. If the render errors, the tip shows the error with a Retry button. If the output returns NULL or empty
text, the tip shows an empty state.
A block, to give to tip_template().
Retry sets the input input$<output>_retry (for an output with the id report_table, input$report_table_retry).
Shiny runs a render again only when something it reads changes, so the render must read that input to run again
on Retry: put input$report_table_retry on a line of its own at the top of the render, as in the example below. If
the server neither starts nor finishes the output within a few seconds of the click, the tip goes back to the error
state with a message that says the server did not run the output again, and Retry stays available.
One output has one place in the page, so a template that many items share shows one output, drawn for one item at
a time. Your server decides for which: ask the items for the "hint" input (tip_on(events = "hint")) and read
input$<id>_hint in the render, as in the second example below; its state is "shown" while the item's hint is
open. When a tip opens for a different item than the one the output was last shown for, the tip shows the loading
state and hides the old content until the server's new value arrives (a server that never reads the open item
sends none, and the old content stays after about a second and a half). A pinned tip sends input$<id>_pin (with
events = "pin"), which the render can read in the same way, and the output of several open pins sits in the tip
that opened last: the others say "Shown in another tip." When the tip that holds the output closes, the output
goes back to the one that held it before.
The tip's own markup is plain attributes and template JSON with no random or per-session ids, so
shiny::renderUI() |> shiny::bindCache() and render*() |> shiny::bindCache() work across sessions.
Other tooltips:
tip_blocks,
tip_define(),
tip_marker(),
tip_more(),
tip_on(),
tip_presets(),
tip_server,
tip_spec(),
tip_style(),
tip_table(),
tip_template(),
tip_theme(),
use_hovercraft()
tip_template( tip_title("{{ label }}"), tip_output("detail_plot") ) tip_template( tip_title("{{ label }}"), tip_output("detail_table", keep_alive = FALSE) ) # Retry: the render reads the retry input, so a click on Retry runs it again. library(shiny) ui <- fluidPage( tip_define(report = tip_template(tip_title("{{ label }}"), tip_output("report_text"))), textOutput("report_text"), tip_on( actionButton("run", "Report"), template = "report", record = list(label = "Report"), id = "run" ) ) server <- function(input, output, session) { tries <- 0 output$report_text <- renderText({ input$report_text_retry tries <<- tries + 1 if (tries == 1) stop("The first try fails") "The report is ready" }) } shinyApp(ui, server) # One output for two items: the render reads the hint input to learn which item is open. ui <- fluidPage( tip_define(detail = tip_template(tip_title("{{ label }}"), tip_output("detail_text"))), textOutput("detail_text"), tip_on( actionButton("a", "Item A"), template = "detail", record = list(label = "A"), id = "a", events = "hint" ), tip_on( actionButton("b", "Item B"), template = "detail", record = list(label = "B"), id = "b", events = "hint" ) ) server <- function(input, output, session) { open_item <- reactiveVal("none") observeEvent(input$a_hint, if (input$a_hint$state == "shown") open_item("A")) observeEvent(input$b_hint, if (input$b_hint$state == "shown") open_item("B")) output$detail_text <- renderText(paste("Details of item", open_item())) } shinyApp(ui, server)tip_template( tip_title("{{ label }}"), tip_output("detail_plot") ) tip_template( tip_title("{{ label }}"), tip_output("detail_table", keep_alive = FALSE) ) # Retry: the render reads the retry input, so a click on Retry runs it again. library(shiny) ui <- fluidPage( tip_define(report = tip_template(tip_title("{{ label }}"), tip_output("report_text"))), textOutput("report_text"), tip_on( actionButton("run", "Report"), template = "report", record = list(label = "Report"), id = "run" ) ) server <- function(input, output, session) { tries <- 0 output$report_text <- renderText({ input$report_text_retry tries <<- tries + 1 if (tries == 1) stop("The first try fails") "The report is ready" }) } shinyApp(ui, server) # One output for two items: the render reads the hint input to learn which item is open. ui <- fluidPage( tip_define(detail = tip_template(tip_title("{{ label }}"), tip_output("detail_text"))), textOutput("detail_text"), tip_on( actionButton("a", "Item A"), template = "detail", record = list(label = "A"), id = "a", events = "hint" ), tip_on( actionButton("b", "Item B"), template = "detail", record = list(label = "B"), id = "b", events = "hint" ) ) server <- function(input, output, session) { open_item <- reactiveVal("none") observeEvent(input$a_hint, if (input$a_hint$state == "shown") open_item("A")) observeEvent(input$b_hint, if (input$b_hint$state == "shown") open_item("B")) output$detail_text <- renderText(paste("Details of item", open_item())) } shinyApp(ui, server)
Lists the presets the tip engine ships, to give as
style = to tip_on() and use_hovercraft(), or as the first
argument of tip_style(). The name of a preset is stable; its values may be tuned between releases.
tip_presets()tip_presets()
A data frame with one row for each preset and the columns name, label (a person's name for it) and
about (one sentence on what it is for).
Other tooltips:
tip_blocks,
tip_define(),
tip_marker(),
tip_more(),
tip_on(),
tip_output(),
tip_server,
tip_spec(),
tip_style(),
tip_table(),
tip_template(),
tip_theme(),
use_hovercraft()
tip_presets()tip_presets()
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.
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() )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() )
id |
The tip's id: the |
... |
Must be empty. It makes a misspelt argument an error. |
row, column
|
The address of a table's tip: |
session |
The Shiny session; the default is the one the call runs in. |
text, template, record, placement
|
For |
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").
NULL, invisibly. These functions are called for their effect on the page.
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()
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) }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) }
Wraps the words of one
tip_table() target (rows, one column of cells, or one column of headers) together
with settings that only that target needs. A setting left as NULL is taken from tip_table(). The API shape may
change in upcoming releases: later versions add more settings.
tip_spec( content, ..., style = NULL, placement = NULL, to = NULL, marker = NULL, more = NULL, pin = NULL, events = NULL )tip_spec( content, ..., style = NULL, placement = NULL, to = NULL, marker = NULL, more = NULL, pin = NULL, events = NULL )
content |
The words of the tip (markdown, with |
... |
Must be empty. It makes a misspelt argument an error. |
style |
How this target's tips look, or |
placement |
Where this tip shows: |
to |
|
marker |
The visible cue for this target's cells or header cells: |
more |
Extra content for the long form of this tip, or |
pin |
Whether a reader can keep this target's tip open: |
events |
The Shiny inputs this target's tips send: one or more of |
Give a spec as rows, or as an entry of a named list given to cells or headers. Plain words and a
tip_template() are accepted in all three places too, and mean "the table's settings".
An object of class hovercraft_spec, to give to tip_table().
Other tooltips:
tip_blocks,
tip_define(),
tip_marker(),
tip_more(),
tip_on(),
tip_output(),
tip_presets(),
tip_server,
tip_style(),
tip_table(),
tip_template(),
tip_theme(),
use_hovercraft()
scores <- data.frame(team = c("Owls", "Foxes"), wins = c(7, 5), note = c("Top", "Late")) DT::datatable(scores) |> tip_table( rows = "**{{ team }}**: {{ wins | number:0 }} wins", cells = list( note = tip_spec( "{{ team }}", more = tip_more("{{ note }}", on = "hover"), style = "sober", placement = "right", marker = "corner" ) ) ) # A row that can be pinned, and a Shiny input that says which row was pinned DT::datatable(scores) |> tip_table( rows = tip_spec("**{{ team }}**: {{ wins | number:0 }} wins", pin = TRUE, events = "pin"), id = "scores_tips" )scores <- data.frame(team = c("Owls", "Foxes"), wins = c(7, 5), note = c("Top", "Late")) DT::datatable(scores) |> tip_table( rows = "**{{ team }}**: {{ wins | number:0 }} wins", cells = list( note = tip_spec( "{{ team }}", more = tip_more("{{ note }}", on = "hover"), style = "sober", placement = "right", marker = "corner" ) ) ) # A row that can be pinned, and a Shiny input that says which row was pinned DT::datatable(scores) |> tip_table( rows = tip_spec("**{{ team }}**: {{ wins | number:0 }} wins", pin = TRUE, events = "pin"), id = "scores_tips" )
Bundles what makes a tip look the way it does: a preset (a named look), a theme (colours, corner and font), a class
on the tip box, and how it enters and how big it is. Give the result as
style = to tip_on() for one tag, or to
use_hovercraft() for the whole page.
A part left out is left alone: it is inherited from the page, or from the page's own bslib variables.
tip_style( preset = NULL, ..., theme = NULL, class = NULL, motion = NULL, gap = NULL, max_width = NULL, pin_width = NULL )tip_style( preset = NULL, ..., theme = NULL, class = NULL, motion = NULL, gap = NULL, max_width = NULL, pin_width = NULL )
preset |
A preset name from |
... |
Must be empty. It makes a misspelt argument an error. |
theme |
A |
class |
Class names for the tip box, |
motion |
How a tip enters: |
gap |
The space between the tag and the tip, in pixels: a whole number from 0 to 24, or |
max_width |
The widest a hint grows, in pixels: a whole number from 160 to 640, or |
pin_width |
The widest a pinned tip grows, in pixels: a whole number from 240 to 720, or |
A value set nearer the tip wins: a tag's style beats the page's. A theme is merged role by role, so a tag that sets
only bg keeps the page's text. A preset is replaced as a whole by the nearer one, and "none" clears an
inherited preset. A theme beats a preset set at the same place or further out, role by role, so
tip_style("sober", theme = ...) is sober with those roles changed; a preset set nearer the tip than a theme beats
that theme.
A hovercraft_style object, to give as style = to tip_on() or use_hovercraft(). Its fields are
internal; pass the object on.
class puts class names on the tip box, so your own CSS can restyle it. Give class names as a vector
(c("wide", "audit-tip")) or as text with spaces ("wide audit-tip"), "" to clear a class the page or a parent
set, or NULL to inherit. A name has letters, digits, - and _ and does not start with a digit, and must not
start with hc-tip, which the tip's own classes use; R stops on a bad name, where the browser would only drop it
with a line in its console. The nearest class wins as a whole and the classes are not added together: a tag's
class = "wide" replaces a page's class = "brand".
motion is how a tip enters: "fade", "slide" (it moves four pixels from its side while it fades) or "none".
gap is the space between the tag and the tip, max_width the widest a hint grows, and pin_width the widest a
pinned tip grows, all in pixels and all whole numbers. R checks them against the ranges in the tip engine's page
contract, so a value outside one stops with an error that names it. A tip is also kept inside the window.
They are written the way a theme is, on the page or on one tag, and a value set nearer the tip wins, one value at a
time: a tag that sets only gap keeps the page's motion. They apply with a preset or without one.
A reader's reduced-motion setting always wins over "fade" and "slide"; the tip engine does this, and nothing here
switches it off.
There is no delay argument: the tip engine reads the delay before a hint shows only from the file of a preset.
A theme given to a tag sets the roles bg, text, border, code_bg, radius, shadow and font. CSS variables
given as a list of names that start with -- reach the tip only from the page, not from a tag, because a tip is
drawn away from its tag.
Other tooltips:
tip_blocks,
tip_define(),
tip_marker(),
tip_more(),
tip_on(),
tip_output(),
tip_presets(),
tip_server,
tip_spec(),
tip_table(),
tip_template(),
tip_theme(),
use_hovercraft()
tip_style("sober") tip_style("sober", theme = tip_theme(light = list(bg = "#1b3a6b", text = "#ffffff"))) tip_style(class = "wide") tip_style(class = "") # clears a class set above tip_style("sober", motion = "slide", max_width = 280) use_hovercraft(style = tip_style(motion = "fade", gap = 10)) tip_on( htmltools::tags$button("Run"), "Runs the **check**", style = tip_style("dense", class = "audit-tip") )tip_style("sober") tip_style("sober", theme = tip_theme(light = list(bg = "#1b3a6b", text = "#ffffff"))) tip_style(class = "wide") tip_style(class = "") # clears a class set above tip_style("sober", motion = "slide", max_width = 280) use_hovercraft(style = tip_style(motion = "fade", gap = 10)) tip_on( htmltools::tags$button("Run"), "Runs the **check**", style = tip_style("dense", class = "audit-tip") )
Built on top of the tip engine, and experimental: the API may change in upcoming releases. Gives the rows of a
table made by
DT::datatable() or reactable::reactable() a tip drawn from the row's own values, and
optionally a tip of their own to chosen cells and header cells. The tips follow the data row, so sorting, filtering
and paging need no code of yours: each row is its own record, whatever place it has on the screen.
tip_table( widget, ..., rows = NULL, cells = NULL, headers = NULL, style = NULL, placement = NULL, marker = NULL, id = NULL, max_pins = NULL )tip_table( widget, ..., rows = NULL, cells = NULL, headers = NULL, style = NULL, placement = NULL, marker = NULL, id = NULL, max_pins = NULL )
widget |
A table made by |
... |
Must be empty. It makes a misspelt argument an error. |
rows |
One string, |
cells |
A named vector or list, one entry per column (by the column's name; a name given twice is an error), for
the cells of that column. Each entry is a string, a
|
headers |
The same for the header cells; a header has no row to read from, so a |
style |
How every tip in the table looks, or |
placement |
Where the tips show: |
marker |
The visible cue on every cell and header cell that has a tip, so a reader can see where the tips are:
|
id |
The id this table's Shiny inputs hang on ( |
max_pins |
|
Known limits: row is the position in the data the table has now, so a pin follows the row number after
replaceData() or a redraw; a DT table in server mode has only the rows of the current page on the screen; and
the table's script does some work for each row on the screen on every change of the data, so page a long table.
tip_table() reads the table's data once in R (for a reactable table it parses all the rows) to check the columns
and values the tips name, so its R time grows with the rows.
A cell's tip wins over its row's, and a row's tip opens at the pointer. The tip of a cell or a header cell points at
its text, not at the whole cell, so a right-aligned number in a wide column, or a right-aligned header, gets a tip
beside the text and not far to its left; there is no argument for it. A target that needs its own settings (style,
placement, marker or more) takes a tip_spec() in place of words. A tip is made of words (markdown)
with
{{ column }} placeholders, or of a tip_template(); every placeholder is checked against the table's columns, and
a miss lists them. Placeholders that start with a dot are kept for hovercraft. A header tip has no row to read from,
so it takes words, or a tip_template() with no placeholders.
Tips also show for the keyboard. A row, a cell or a header cell cannot take focus by itself, so tip_table() gives
the table one tab stop, and the arrow keys move between the rows, cells and header cells that have a tip: left and
right inside a row (the row first, then its cells), up and down between rows to the same column, Home and End to the
ends of the row, and Ctrl with Home or End to the ends of the table. The tip shows for what has focus. A header that
its widget already makes focusable (the sortable headers of DT) keeps its own tab stop. Enter and Space do not
select a row. A click on a row selects it in both widgets, so a row's tip does not pin on click.
Pins: with tip_spec(pin = TRUE) as rows, a reader can keep a row's tip open. The tip that shows on hover or
focus gets a small pin handle in its corner, the same as tip_on()'s (pin = TRUE): a click or tap on it pins the
row's tip, and the tip's own close button, Escape or a click away closes it (a click away does not close a panel
that opens in place, see below). The pin key P pins the tip of the row that has focus or that the pointer rests
on, or of the row a focused cell belongs to; a cell or a header cell has no pin of its own ("only rows pin for
now"), so P while the pointer rests on a cell that has a tip of its own pins nothing. A long form (more) opens
with its "More" button, or with the M key when the focus is on the row, a cell or a header cell, or the pointer
rests on it. A tap on a row shows its tip and a tap on the handle pins it. The handle is not a column and not a
tab stop, so the table keeps its one tab stop and its columns; keyboard readers use the key, which
each row that can pin announces as aria-keyshortcuts. A pin follows its row. It stays on a row when DT sorts
(client and server mode), and on the same row number when DT draws the table again or DT::replaceData() or
reactable::updateReactable(data = ) give it new data, with the new values in its tip. It closes when its row
leaves the page (a filter or another page in DT, another page in reactable), when reactable shows another row
in the row's place, when the table goes, and when a click lands elsewhere. The input then says why: DT closes a
pin of a row that left the page itself (reason "gone", by "data"); reactable keeps its row nodes and gives
them other rows, so the layer closes the pin through the tip engine's host command (reason "host", by
"host", via "command"). A server that acts on by == "data" sees the two widgets differently.
The widget, with the tips added.
tip_spec(events = ) on rows turns on inputs that belong to the table, one per event and not one per row, named
after the table's id: input$<id>_hint, input$<id>_pin and input$<id>_copy. Each is NULL until its first
event. Its value is the event that just happened, with the fields of tip_on()'s (state, text, by, via and
reason), and says which tip it was:
target: "row" ("cell" and "header" are kept for later; only rows send events for now);
row: the row's place in the data the widget has now, counted from 1, in client mode and in server mode alike,
and not the row's place on the screen: after a sort, the third data row is still 3. It is NULL for a header.
After DT::replaceData(), reactable::updateReactable(data = ) or a re-render with other data, row 3 is whatever
is third now, so do not keep it as a record's id;
column: the data column's name (the name in the data frame, not the header's text), or NULL for a row;
id: the tip's id. How it is written is not part of the API.
input$<id>_pinned (with events = "pin") is what is pinned now: a list of such addresses (target, row,
column, id), the oldest pin first. It is NULL until the first pin event, and an empty list once nothing is
pinned. It is sent in the same batch as _pin, and a value equal to the one before does not fire an observer again.
Read it with length(input$scores_pinned): it holds as many addresses as the table has pins open (see max_pins).
For a tag of tip_on() with events = "pin", input$<id>_pinned is TRUE or FALSE (read it with
isTRUE(input$run_pinned)).
input$<id>_pin and input$<id>_hint are told apart by state, whose values may grow in a later version. A pin's
state is "pinned", "closed" or "updated" (the tip is pinned and was drawn again because its words changed:
an app that only tests for "closed" should not take it for a pin); a hint's is "shown" or "hidden". The values
of by are "reader", "data" (the page changed under the tip) and "host" (a command of the page did it). The
values of reason (the same for the inputs of tip_on()) are, for a pin, "select" (the same element again),
"escape", "button" (the tip's close button), "outside" (a click away), "replaced" (another tip was pinned),
"gone" (the row left the page), "below" (a layer around it closed), "host" (a command of the page closed it)
and "redraw" (the tip was drawn again with other host slots, by = "data"); for a hint, "leave" (the pointer
left), "blur" (the focus left), "escape", "outside", "pinned" (the hint became a pin), "replaced",
"gone" and "host". reason is NULL when a tip opens.
With
tip_spec(to = "in_place", pin = TRUE) as rows (and the table's id), a row's pinned tip is drawn as a panel
under its row, as wide as the table's visible part, in DT and in reactable. The hover tip still floats. The pin
handle or the pin key opens it, and it holds what any pinned tip holds: its blocks, the long form with its "More"
button, a tip_output(). The widget's own inputs (rows_selected, cell_clicked) are not touched by a click in it.
It follows the pin: DT moves the panel with its row when the table sorts, and puts it back after every draw, in
server mode too; a filter or another page that takes the row off the page closes it (reason "gone").
DT::replaceData() keeps it on the same row number. reactable closes it when it shows other rows in the row's
node (reason "host"), as for a floating pin, and keeps it when it is given new data with
updateReactable(data = ). A server-mode DT drawn again by renderDT() closes it, as it does a floating pin. A
panel counts in use_hovercraft(max_pins = ) and tip_table(max_pins = ) like any pin: the oldest closes (reason
"replaced") and its panel goes with it.
A click away does not close a panel: it closes by its close button, Escape, the pin limit, or its row going. The
pin key on a row whose panel is open does nothing. Escape on a row that has no pin of its own closes the newest
pin, as for floating pins. With scrollX the panel stays at the left edge of the visible part. The FixedColumns
extension of DT (it copies the rows) stops with an error; responsive and RowGroup of DT, reactable's
groupBy, and screen readers are not covered. A click inside a DT panel is stopped at the panel's row, so a
handler that the page delegates on document does not see it.
What works, each checked in a browser:
DT, in client mode and in server mode under Shiny, with scrollX, scrollY, fixedHeader, colReorder and
responsive. With responsive, a column folded into the details row has no tip there; the row's tip is
unchanged.
reactable, with sorting, filtering, paging, row selection (a click selects the row and its tip stays),
groupBy (the rows inside a group have tips, the group's own row has none), details (the details panel has
none) and filterable = TRUE (the tip of a header cell stays on the header cell; the filter box under it has no
tip and is not described twice). DT's filter row has none either.
An id inside a module: give the plain id inside renderDT() or renderReactable(), and ns() in the
module's UI function (see id).
Tables that Shiny updates with new data: DT::replaceData() (it works in server mode) with the user's own data
frame, and reactable::updateReactable(data = ). The tips follow the new rows, as they do after sorting,
filtering and paging.
Not supported: a DT table with its own createdRow or initComplete option; a reactable column whose
headerClass is a JavaScript function; any other widget.
Large tables: tip_table() adds nothing to the data of the page, since each tip reads its values from the table's
own data in the browser. A reactable row carries the values its tips read in its class, as well as in the engine's
attribute, so they sit twice in the page for every row that is drawn: page the table. A table with every row drawn
at once is slow in DT when cells or headers have tips (a table of 2,000 rows with a row tip and three cell tips
took about a second to draw, five times as long as without tips; thousands of rows take seconds); page it, or tip
its rows only.
Give tip_table() the finished widget, last in the pipe or at least after the columns are settled.
DT::datatable() keeps its columns and its inputs as they are: tip_table() adds no column and changes no event
(a table with its own createdRow or initComplete option is refused for now). reactable::reactable() gets its
own rowClass, class and headerClass added to yours; the class of a row holds the values its tips read, so it
changes with the data.
Other tooltips:
tip_blocks,
tip_define(),
tip_marker(),
tip_more(),
tip_on(),
tip_output(),
tip_presets(),
tip_server,
tip_spec(),
tip_style(),
tip_template(),
tip_theme(),
use_hovercraft()
scores <- data.frame(team = c("Owls", "Foxes"), wins = c(7, 5), losses = c(3, 5)) DT::datatable(scores) |> tip_table( rows = tip_spec( "**{{ team }}**: {{ wins | number:0 }} wins, {{ losses | number:0 }} losses", pin = TRUE, events = "pin" ), headers = c(wins = "Games won this season"), id = "scores_tips" )scores <- data.frame(team = c("Owls", "Foxes"), wins = c(7, 5), losses = c(3, 5)) DT::datatable(scores) |> tip_table( rows = tip_spec( "**{{ team }}**: {{ wins | number:0 }} wins, {{ losses | number:0 }} losses", pin = TRUE, events = "pin" ), headers = c(wins = "Games won this season"), id = "scores_tips" )
A template is a list of blocks, shown in order. Name it with
tip_define() and use the name in tip_on(), or give
the template itself to template = of tip_on(). A block can be made with tip_title() and the other block
functions, or written as a plain list such as list(type = "text", text = "..."); both are checked in the same way.
tip_template(..., head = NULL, body = NULL, foot = NULL)tip_template(..., head = NULL, body = NULL, foot = NULL)
... |
One or more blocks in order (cannot be named; use |
head |
Optional block or list of blocks drawn at the top of the tip (for example a |
body |
Optional block or list of blocks drawn in the middle of the tip. Cannot be combined with |
foot |
Optional block or list of blocks drawn at the bottom of the tip below a subtle divider. |
Blocks can be given in order through ..., or placed into the named slots head, body and foot. Each slot
takes one block or a list of blocks; foot is drawn below a thin divider in muted text, suited for a source line or
footnote. Do not pass both positional blocks in ... and body.
A template, to give to tip_define() or to template = of tip_on().
Other tooltips:
tip_blocks,
tip_define(),
tip_marker(),
tip_more(),
tip_on(),
tip_output(),
tip_presets(),
tip_server,
tip_spec(),
tip_style(),
tip_table(),
tip_theme(),
use_hovercraft()
tip_template( tip_title("{{ label }}"), tip_text("{{ differences | number:0 }} differences"), list(type = "badge", text = "{{ status }}") ) tip_template( head = list(tip_title("{{ label }}"), tip_badge("{{ status }}", status = "{{ tone }}")), body = tip_fields(Records = "{{ records | number:0 }}"), foot = tip_text("Source: {{ source }}") )tip_template( tip_title("{{ label }}"), tip_text("{{ differences | number:0 }} differences"), list(type = "badge", text = "{{ status }}") ) tip_template( head = list(tip_title("{{ label }}"), tip_badge("{{ status }}", status = "{{ tone }}")), body = tip_fields(Records = "{{ records | number:0 }}"), foot = tip_text("Source: {{ source }}") )
Sets how the tips look: the fill, words, border and code background, the corner, the shadow and the typeface, for
light and for dark. A role left out keeps what the page gives: the tip reads Bootstrap's variables where the page has
them (bslib), so a page that already has a
bslib::bs_theme() needs no theme, and its tips follow light and dark on
their own. Use a theme when the tips must look different from the page, or when the page has no bslib. Give the
result to use_hovercraft() once, in the page's UI, or to tip_on() for one tag, as style =.
tip_theme(..., light = NULL, dark = NULL, mode = "auto")tip_theme(..., light = NULL, dark = NULL, mode = "auto")
... |
Must be empty. It makes a misspelt argument an error. |
light, dark
|
Named lists of roles, or |
mode |
|
The roles are bg (the tip's fill), text (its words), border (its border, seen in forced-colours mode and in a
tip that stays open), code_bg (behind code), radius (the corner), shadow and font. Colours may be names, hex,
grDevices::rgb() output, "rgba(0, 0, 0, 0.8)" text or three numbers from 0 to 255. A value that is a CSS
variable, "--team-blue" or "var(--team-blue)", is read by the browser where the page defines it; R cannot check
it. A theme can also be a bslib::bs_theme() or a plain list, see tip_style().
A role set in light and not in dark is used in dark mode too, so a brand colour set once holds in both modes.
The tip has a small arrow pointing at its tag. It takes the colour of the tip, so it is drawn only when the bg is
opaque: with a translucent bg ("rgba(0, 0, 0, 0.8)") the tip has no arrow.
A hovercraft_theme object, to give as style = to use_hovercraft() or tip_on(), or to
tip_style(). Its fields are internal; pass the object on.
The words of a tip must be readable on its fill. For each mode, the text on the bg (and on the code_bg, if you
give one) is measured, and a ratio below 4.5:1, the usual level for text, gives a warning of class
hovercraft_contrast; the colours are kept. A role you leave out is taken to be what Bootstrap's default theme
gives, a shade of the page: Bootstrap's tertiary background with the page's text colour (a #f8f8f8 fill with
#1d1f21 words in light mode, #292d34 with #dee2e6 in dark mode). CSS variables
cannot be measured and are skipped. A translucent bg is measured over the page's colour (white, or #1d1f21 in
dark mode), and a translucent code_bg over the bg. Set options(hovercraft.contrast_warnings = FALSE) to turn
the warnings off, or
silence only them:
withCallingHandlers(
tip_theme(light = list(bg = "#ffffff", text = "#dddddd")),
hovercraft_contrast = function(w) invokeRestart("muffleWarning")
)
Other tooltips:
tip_blocks,
tip_define(),
tip_marker(),
tip_more(),
tip_on(),
tip_output(),
tip_presets(),
tip_server,
tip_spec(),
tip_style(),
tip_table(),
tip_template(),
use_hovercraft()
tip_theme() tip_theme(light = list(bg = "#1b3a6b", text = "#ffffff", radius = 8)) tip_theme( light = list(bg = "#1b3a6b", text = "#ffffff"), dark = list(bg = "#9ec5fe", text = "#0b1f3a"), mode = "auto" ) tip_theme(light = list(bg = "--brand-blue", font = "Georgia, serif"))tip_theme() tip_theme(light = list(bg = "#1b3a6b", text = "#ffffff", radius = 8)) tip_theme( light = list(bg = "#1b3a6b", text = "#ffffff"), dark = list(bg = "#9ec5fe", text = "#0b1f3a"), mode = "auto" ) tip_theme(light = list(bg = "--brand-blue", font = "Georgia, serif"))
for the page's
style given as a preset name; max_pins, keys and labels are
.
The engine's script and CSS, ready to add to a page.
tip_on() and tip_define() attach it for you; use this when
you build the page's head yourself, or to give the page a look. The dependency is versioned with the engine, not
with this package. The engine reads Bootstrap's colours where the page has them (bslib), and plain colours otherwise.
Which names on the page your own CSS and JavaScript may rely on, and which are internal, is in the section "What is
public on the page" of the
README.
use_hovercraft(style = NULL, max_pins = 1, keys = TRUE, labels = NULL)use_hovercraft(style = NULL, max_pins = 1, keys = TRUE, labels = NULL)
style |
A tag's own |
max_pins |
|
keys |
|
labels |
|
A list of htmltools::htmlDependency() objects: the engine's script and style sheet, then, with a style
that sets something, hovercraft-style, which holds the page's theme CSS and sets the page's preset and class as
the engine's attributes on the page, with a max_pins, keys or labels that is given one of their own, and last
hovercraft-runtime, which starts the engine and the layers (the names of these dependencies are internal and may
change). Put it
once in the page's UI, for example bslib::page_fluid(use_hovercraft(style = "sober"), ...).
Nothing in them is inline script or style: they are files and data, so a page served with
Content-Security-Policy: script-src 'self'; style-src 'self' works. A style sheet that is made from a theme is
data too, which a script applies as a constructed style sheet; it comes after the page's own style sheets in the
cascade. The scripts read their names and tip_define()'s templates from JSON, which a browser does not run, and
set styles through the browser's style object, which a policy on inline markup does not cover. Every dependency is
a folder of the installed package, so a cached document or a shared cache can use them in another R process.
What such a page still needs, because it is not hovercraft's markup:
a policy that has default-src or img-src must also allow data: images, or three small icons are not
drawn: the lock before a reason (when_disabled), the pin button (pin) and the built-in icon of
marker = "icon". The words of the first two still show; the marker has no words, so an icon marker is then
invisible (an icon of your own, given as a tag, is not affected);
a style attribute written in markup, such as the width that shiny::actionButton() and shiny::plotOutput()
write, is blocked by style-src 'self' whoever writes it. style-src-attr 'unsafe-inline' allows them, and
nothing else, or the page can use classes and a style sheet instead.
Other tooltips:
tip_blocks,
tip_define(),
tip_marker(),
tip_more(),
tip_on(),
tip_output(),
tip_presets(),
tip_server,
tip_spec(),
tip_style(),
tip_table(),
tip_template(),
tip_theme()
use_hovercraft() use_hovercraft(style = "modern") use_hovercraft(style = tip_theme(light = list(bg = "#1b3a6b", text = "#ffffff"))) use_hovercraft(style = tip_style("sober", theme = list("--hovercraft-tip-radius" = "8px"))) use_hovercraft(max_pins = 3, keys = c(pin = FALSE)) use_hovercraft( labels = c(copy = "Copy code", close = "Dismiss", more_pinned = "Open to read more") )use_hovercraft() use_hovercraft(style = "modern") use_hovercraft(style = tip_theme(light = list(bg = "#1b3a6b", text = "#ffffff"))) use_hovercraft(style = tip_style("sober", theme = list("--hovercraft-tip-radius" = "8px"))) use_hovercraft(max_pins = 3, keys = c(pin = FALSE)) use_hovercraft( labels = c(copy = "Copy code", close = "Dismiss", more_pinned = "Open to read more") )