Tooltips_and_Popovers {shinyBS} | R Documentation |
Tooltips and Popovers
Description
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.
Details
You can create tooltips and popovers from either the UI script or within the
Server logic. bsTooltip
and bsPopover
are used in
the UI, and addTooltip
and addPopover
are used in
the Server logic. tipify
and popify
can be used
within the UI or from within a renderUI
in the Server logic. They
also have the added advantage of not requiring that the UI element have an ID
attribute.
Components
There are eight functions in the Tooltips and Popovers family:
bsTooltip
Used in the UI to add a tooltip to an element in your UI.
bsPopover
Used in the UI to add a popover to an element in your UI.
tipify
Wrap any UI element in
tipify
to add a tooltip to the wrapped element. Preferred for elemented created withrenderUI
.popify
Wrap any UI element in
popify
to add a popover to the wrapped element. Preferred for elements created withrenderUI
.addTooltip
Used in the Server logic to add a tooltip to an element in your UI.
addPopover
Used in the Server logic to add a popover to an element in your UI.
removeTooltip
Used in the Server logic to remove a tooltip from an element in your UI.
removePopover
Used in the Server logic to remove a popover from an element in your UI.
Changes
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 Twitter Bootstrap 3 documentation for more
details.
Note
Tooltips and Popovers cannot contain shiny inputs or outputs.
There must be at least one shinyBS
component in the UI of your
app in order for the necessary dependencies to be loaded. Because of this,
addTooltip
and addPopover
will not work if they
are the only shinyBS components in your app.
Tooltips and popovers may not work on some of the more complex shiny inputs or outputs. If you encounter a problem with tooltips or popovers not appearing please file a issue on the github page so I can fix it.
Run bsExample("Tooltips_and_Popovers")
for an example
of Tooltips_and_Popovers
functionality.
See Also
Other Tooltips_and_Popovers: addPopover
;
addTooltip
; bsPopover
;
bsTooltip
; popify
;
removePopover
; removeTooltip
;
tipify
Examples
library(shiny)
library(shinyBS)
app = 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"),
uiOutput("uiExample")
)
)
),
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')
})
output$uiExample <- renderUI({
tags$span(
popify(bsButton("pointlessButton", "Button", style = "primary", size = "large"),
"A Pointless Button",
"This button is <b>pointless</b>. It does not do <em>anything</em>!"),
tipify(bsButton("pB2", "Button", style = "inverse", size = "extra-small"),
"This button is pointless too!")
)
})
addPopover(session, "distPlot", "Data", content = paste0("<p>Waiting time between ",
"eruptions and the duration of the eruption for the Old Faithful geyser ",
"in Yellowstone National Park, Wyoming, USA.</p><p>Azzalini, A. and ",
"Bowman, A. W. (1990). A look at some data on the Old Faithful geyser. ",
"Applied Statistics 39, 357-365.</p>"), trigger = 'click')
}
)
## Not run:
runApp(app)
## End(Not run)