popover: Create a Bootstrap 4 popover from the UI side

Description Usage Arguments Note Examples

View source: R/feedbacks.R

Description

This replaces the shinyBS popover feature that is not compatible with Bootstrap 4

addPopover adds a popover to the given target.

removePopover destroys the current targeted popover.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
popover(tag, content, title, placement = c("top", "bottom", "left", "right"))

addPopover(
  id = NULL,
  selector = NULL,
  options,
  session = shiny::getDefaultReactiveDomain()
)

removePopover(id, session = shiny::getDefaultReactiveDomain())

Arguments

tag

Popover target.

content

Popover content.

title

Popover title.

placement

Popover placement: "top", "bottom", "left" or "right".

id

Popover target id.

selector

jQuery selector. Allow more customization for the target (nested tags).

options

List of options to pass to the popover. See https://getbootstrap.com/docs/4.0/components/popovers/.

session

Shiny session object.

Note

popover does not automatically handles tooltip removal and must be seperately implemented. If the dashboardHeader help parameter is TRUE, all popovers may be enabled or disabled depending on the switch value, which may solve this problem. This allows to toggle popovers whenever required.

This replaces the shinyBS popover feature that is not compatible with Bootstrap 4

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
if (interactive()) {
  library(shiny)
  library(bs4Dash)

  shinyApp(
    ui = dashboardPage(
      header = dashboardHeader(),
      sidebar = dashboardSidebar(),
      controlbar = dashboardControlbar(),
      footer = dashboardFooter(),
      title = "Popover UI",
      body = dashboardBody(
        popover(
          actionButton("goButton", "Click me to see the popover!"),
          title = "My popover",
          placement = "right",
          content = "Vivamus sagittis lacus vel augue laoreet rutrum faucibus."
        )
      )
    ),
    server = function(input, output) {}
  )
}
if (interactive()) {
  library(shiny)
  library(bs4Dash)

  shinyApp(
    ui = dashboardPage(
      header = dashboardHeader(),
      sidebar = dashboardSidebar(),
      controlbar = dashboardControlbar(),
      footer = dashboardFooter(),
      title = "Popover server",
      body = dashboardBody(
        sliderInput("obs", "Number of observations:",
          min = 0, max = 1000, value = 500
        ),
        plotOutput("distPlot")
      )
    ),
    server = function(input, output, session) {
      output$distPlot <- renderPlot({
        hist(rnorm(input$obs))
      })

      observeEvent(input$obs, {
        if (input$obs > 500) {
          addPopover(
            id = "distPlot",
            options = list(
              content = "Vivamus sagittis lacus vel augue laoreet rutrum faucibus.",
              title = "Server popover",
              placement = "bottom",
              trigger = "hover"
            )
          )
        } else {
          removePopover(id = "distPlot")
        }
      })
    }
  )
}

bs4Dash documentation built on July 23, 2021, 5:06 p.m.