Turn the mascot into a button for one action of your Shiny app, such as
opening a help panel or a chat. Pass it as click to mascot() or
update_mascot(), and handle the click in your server with
shiny::observeEvent(input$<id>_click, ...). For a choice of several actions,
use mascot_popup_menu() instead.
Arguments
- label
The action's name: one string, not blank, that says what a click does, such as
"Open help". Screen readers announce the mascot as a button with this name, and the tooltip shows it.NULL(the default) makes an empty helper: inupdate_mascot(), it removes the click, so the mascot is a picture again. Withlabel = NULL, settingtooltipordisabledyourself is an error; usemascot_action()without options to remove the click.- ...
Must be empty. Forces the arguments after it to be named.
- tooltip
A flag.
TRUE(the default) shows the label in a tooltip when the pointer rests on the mascot or the keyboard focuses it.FALSEhides the tooltip; screen readers still announce the label.- disabled
A flag.
TRUEkeeps the mascot a button that does nothing: clicks are not sent, and screen readers announce the button as unavailable. Defaults toFALSE. Use it while the action makes no sense, such as during a long task, and sendmascot_action(..., disabled = FALSE)afterwards.
Details
What a click sends. Every activation of the button sets
input$<id>_click to the number of activations since the mascot appeared, so
shiny::observeEvent() runs each time. An activation is a click or tap, Enter
or Space while the mascot has keyboard focus, or a screen reader's activate
command. Holding a key down counts once. Opening and closing a
mascot_popup_menu() never sets this input. Dragging a floating mascot, clicking
elsewhere, pressing Escape, the minimise and restore buttons and updates from
the server never count. In a module, use ns("helper") in the UI and read
input$helper_click in that module's server.
Without a click. The default, click = NULL in mascot(), keeps the
mascot a picture: keyboard focus skips it and it sends no clicks. Use a click
only when it does something, so keyboard users never land on a control that
does nothing.
The tooltip shows the label next to the mascot, on the side with room. It stays while the pointer is over the mascot or the tooltip, and Escape hides it without moving the focus. It never shows on touch screens or while a menu or bubble is open. On static pages the mascot stays a picture.
See also
mascot(), update_mascot(), mascot_popup_menu()
Other mascot helpers:
mascot_anchors(),
mascot_bubble(),
mascot_character(),
mascot_characters(),
mascot_check_character(),
mascot_colour_roles(),
mascot_families(),
mascot_gesture(),
mascot_gestures(),
mascot_mood(),
mascot_moods(),
mascot_motion_settings(),
mascot_palettes(),
mascot_placement(),
mascot_popup_menu(),
mascot_preview(),
mascot_read_character(),
mascot_size(),
mascot_status(),
mascot_theme()
Examples
mascot_action("Open help")
#> mascot_action("Open help")
mascot_action("Open help", tooltip = FALSE)
#> mascot_action("Open help", tooltip = FALSE)
mascot_action()
#> mascot_action()
ui <- mascot("helper", click = "Open help")
if (FALSE) { # interactive()
shiny::shinyApp(
shiny::fluidPage(mascot("helper", click = "Open help")),
function(input, output, session) {
shiny::observeEvent(input$helper_click, {
shiny::showModal(shiny::modalDialog("Help for this app"))
})
}
)
}
