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. list("bsTooltip") and list("bsPopover") are used in the UI, and list("addTooltip") and list("addPopover") are used in the Server logic.

Components

bsTooltip

bsTooltip is used within the UI of an app to add a tooltip to a Shiny input or output.

Usage

bsTooltip(id, title, placement = "bottom", trigger = "hover",
  options = NULL)

Parameters

id
The id of the element to attach the tooltip to.
title
The content of the tooltip.
placement
Where the tooltip should appear relative to its target (top, bottom, left, or right). Defaults to "bottom".
trigger
What action should cause the tooltip to appear? (hover, focus, click, or manual. Defaults to "hover".
options
A named list of additional options to be set on the tooltip.

addTooltip

addTooltip is used within the Server logic of an app to add a tooltip to a Shiny input or output.

Usage

addTooltip(session, id, title, placement = "bottom", trigger = "hover",
  options = NULL)

Parameters

session
The session object passed to function given to shinyServer.
id
The id of the element to attach the tooltip to.
title
The content of the tooltip.
placement
Where the tooltip should appear relative to its target (top, bottom, left, or right). Defaults to "bottom".
trigger
What action should cause the tooltip to appear? (hover, focus, click, or manual. Defaults to "hover".
options
A named list of additional options to be set on the tooltip.

removeTooltip

removeTooltip is used within the Server logic of an app to remove an existing tooltip from a Shiny input or output.

Usage

removeTooltip(session, id)

Parameters

session
The session object passed to function given to shinyServer.
id
The id of the element to remove the tooltip from.

bsPopover

bsPopover is used within the UI of an app to add a popover to a Shiny input or output.

Usage

bsPopover(id, title, content, placement = "bottom", trigger = "hover",
  options = NULL)

Parameters

id
The id of the element to attach the popover to.
title
The title of the popover.
content
The main content of the popover.
placement
Where the popover should appear relative to its target (top, bottom, left, or right). Defaults to "bottom".
trigger
What action should cause the popover to appear? (hover, focus, click, or manual. Defaults to "hover".
options
A named list of additional options to be set on the popover.

addPopover

addPopover is used within the Server logic of an app to add a popover to a Shiny input or output.

Usage

addPopover(session, id, title, content, placement = "bottom",
  trigger = "hover", options = NULL)

Parameters

session
The session object passed to function given to shinyServer.
id
The id of the element to attach the popover to.
title
The title of the popover.
content
The main content of the popover.
placement
Where the popover should appear relative to its target (top, bottom, left, or right). Defaults to "bottom".
trigger
What action should cause the popover to appear? (hover, focus, click, or manual. Defaults to "hover".
options
A named list of additional options to be set on the popover.

removePopover

removePopover is used within the Server logic of an app to remove an existing popover from a Shiny input or output.

Usage

removePopover(session, id)

Parameters

session
The session object passed to function given to shinyServer.
id
The id of the element to remove the popover from.

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 for more details.

Example



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') } )