Tooltips and Popovers allow you to add additional information about controls or outputs without cluttering up your user interface. You can add a tooltip to a button that displays on hover and better explains what the button will do, or you could add a popover to an output providing further analysis of that output.
list("bsTooltip")
and list("bsPopover")
are used in
the UI, and list("addTooltip")
and list("addPopover")
are used in
the Server logic.
bsTooltip
is used within the UI of an app to add a tooltip to a Shiny
input or output.
bsTooltip(id, title, placement = "bottom", trigger = "hover",
options = NULL)
id
title
placement
top
, bottom
, left
, or right
). Defaults to "bottom"
.trigger
hover
,
focus
, click
, or manual
. Defaults to "hover"
.options
addTooltip
is used within the Server logic of an app to add a tooltip to a Shiny
input or output.
addTooltip(session, id, title, placement = "bottom", trigger = "hover",
options = NULL)
session
id
title
placement
top
, bottom
, left
, or right
). Defaults to "bottom"
.trigger
hover
,
focus
, click
, or manual
. Defaults to "hover"
.options
removeTooltip
is used within the Server logic of an app to remove an
existing tooltip from a Shiny input or output.
removeTooltip(session, id)
session
id
bsPopover
is used within the UI of an app to add a popover to a Shiny
input or output.
bsPopover(id, title, content, placement = "bottom", trigger = "hover",
options = NULL)
id
title
content
placement
top
, bottom
, left
, or right
). Defaults to "bottom"
.trigger
hover
,
focus
, click
, or manual
. Defaults to "hover"
.options
addPopover
is used within the Server logic of an app to add a popover to a Shiny
input or output.
addPopover(session, id, title, content, placement = "bottom",
trigger = "hover", options = NULL)
session
id
title
content
placement
top
, bottom
, left
, or right
). Defaults to "bottom"
.trigger
hover
,
focus
, click
, or manual
. Defaults to "hover"
.options
removePopover
is used within the Server logic of an app to remove an
existing popover from a Shiny input or output.
removePopover(session, id)
session
id
An options
argument has been added to the creation functions to allow
advanced users more control over how the tooltips and popovers appear. See
the for more
details.
library(shiny)
library(shinyBS)
shinyApp(
ui =
fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
bsTooltip("bins", "The wait times will be broken into this many equally spaced bins",
"right", options = list(container = "body"))
),
mainPanel(
plotOutput("distPlot")
)
)
),
server =
function(input, output, session) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
addPopover(session, "distPlot", "Data", content = paste0("Waiting time between ",
"eruptions and the duration of the eruption for the Old Faithful geyser ",
"in Yellowstone National Park, Wyoming, USA.
Azzalini, A. and ",
"Bowman, A. W. (1990). A look at some data on the Old Faithful geyser. ",
"Applied Statistics 39, 357-365.
"), trigger = 'click')
}
)