Skip to contents

The studio guide for mascot_popup_menu(). The same page is read in the mascot studio.

Try it live. The mascot studio shows this function with live controls and the generated code. In an R session with the optional packages bslib and knitr installed, run:
mascot::mascot_studio(fn = "mascot_popup_menu")
It opens on this function's guide; change a control and watch the mascot.

From a click to your server

The visitor picks
Finish review
→
input$helper_menu
becomes "finish"
→
Your observeEvent()
decides
→
update_mascot()
answers

Long status

The menu opens from the mascot’s position on the screen and falls back to the opposite side when the chosen side has no room. A long status makes the mascot taller, so choose a corner, then open the live mascot’s menu to see where it lands.

Your server code for these items

For an item named finish and labelled “Finish review”, the server can answer like this:

shiny::observeEvent(input$helper_menu, {
  switch(input$helper_menu,
    finish = mascot::update_mascot("helper", mood = "happy")
  )
})

input$&lt;id&gt;_menu vs input$<id>_click. Menus never set input$<id>_click; only mascot_action() does. Choosing an item sets input$<id>_menu to the chosen item’s id. Opening and closing the menu sends no Shiny input.

Supply menu items when setting options. Setting disabled, direction, label or tooltip requires items. To remove the click behaviour, pass click = mascot_popup_menu() to update_mascot().

Keyboard. Tab to the mascot’s menu button, then Enter or Space opens it; arrow keys move between items; Escape closes it.

Warnings, errors and common mistakes

mascot_popup_menu(c("has spaces" = "Action"))
Error: could not find function "mascot_popup_menu"
mascot_popup_menu(c(about = "About"), "top")
Error: could not find function "mascot_popup_menu"