popover | R Documentation |
Display additional information when clicking on a UI element (typically a button).
popover(
trigger,
...,
title = NULL,
id = NULL,
placement = c("auto", "top", "right", "bottom", "left"),
options = list()
)
toggle_popover(id, show = NULL, session = get_current_session())
update_popover(id, ..., title = NULL, session = get_current_session())
trigger |
The UI element to serve as the popover trigger (typically a
|
... |
UI elements for the popover's body. Character strings are
automatically escaped unless marked as
|
title |
A title (header) for the popover. To remove a header
with |
id |
A character string. Required to re-actively respond to the
visibility of the popover (via the |
placement |
The placement of the popover relative to its trigger. |
options |
A list of additional options. |
show |
Whether to show ( |
session |
A Shiny session object (the default should almost always be used). |
popover()
: Add a popover to a UI element
toggle_popover()
: Programmatically show/hide a popover.
update_popover()
: Update the contents of a popover.
In addition to clicking the close_button
, popovers can be closed by
pressing the Esc/Space key when the popover (and/or its trigger) is
focused.
Like other bslib components, popovers can be themed by supplying
relevant theming variables
to bs_theme()
,
which effects styling of every popover on the page.
To style a specific popover differently from other popover, utilize the customClass
option:
popover( "Trigger", "Popover message", options = list(customClass = "my-pop") )
And then add relevant rules to bs_theme()
via bs_add_rules()
:
bs_theme() |> bs_add_rules(".my-pop { max-width: none; }")
Because the user needs to interact with the trigger
element to see the popover, it's best practice to use an element that is typically accessible via keyboard interactions, like a button or a link.
If you use a non-interactive element, like a <span>
or text, bslib will automatically add the tabindex="0"
attribute to the trigger element to make sure that users can reach the element with the keyboard.
This means that in most cases you can use any element you want as the trigger.
One place where it's important to consider the accessibility of the trigger is when using an icon without any accompanying text. In these cases, many R packages that provide icons will create an icon element with the assumption that the icon is decorative, which will make it inaccessible to users of assistive technologies.
When using an icon as the primary trigger, ensure that the icon does not have aria-hidden="true"
or role="presentation"
attributes.
Icon packages typically provide a way to specify a title for the icon, as well as a way to specify that the icon is not decorative.
The title should be a short description of the purpose of the trigger, rather than a description of the icon itself.
If you're using bsicons::bs_icon()
, provide a title
.
If you're using fontawesome::fa()
, set a11y = "sem"
and provide a title
.
For example:
popover( bsicons::bs_icon("gear", title = "Settings"), title = "Settings", sliderInput("n", "Number of points", 1, 100, 50) )
popover( fontawesome::fa("gear", a11y = "sem", title = "Settings"), title = "Settings", sliderInput("n", "Number of points", 1, 100, 50) )
Popovers are based on Bootstrap's Popover component. See the bslib website for an interactive introduction to tooltips and popovers.
tooltip()
provides an alternative way to display informational
text on demand, typically when focusing or hovering over a trigger element.
Other Components:
accordion()
,
card()
,
tooltip()
,
value_box()
popover(
shiny::actionButton("btn", "A button"),
"Popover body content...",
title = "Popover title"
)
library(shiny)
ui <- page_fixed(
card(class = "mt-5",
card_header(
popover(
uiOutput("card_title", inline = TRUE),
title = "Provide a new title",
textInput("card_title", NULL, "An editable title")
)
),
"The card body..."
)
)
server <- function(input, output) {
output$card_title <- renderUI({
list(input$card_title, bsicons::bs_icon("pencil-square"))
})
}
shinyApp(ui, server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.