rstudio / bslib

Tools for theming Shiny and R Markdown via Bootstrap 3, 4, or 5.
https://rstudio.github.io/bslib/
Other
475 stars 57 forks source link

Both tooltip and popover don't work when used with nav_insert #1019

Closed Milko-B closed 6 months ago

Milko-B commented 6 months ago

Describe the problem

Both popover() and tooltip() don't work when inserting UI using nav_insert(). They are no longer interactable elements.

In the reprex below, I have build a simple app which uses page_navbar() to initially show only one tab. Both the tooltip, and the popover work as intended. However, by pressing the button in the sidebar we add another page with the exact same UI. In this second page, both elements cease to work.

library(shiny)
library(bslib)

ui <- fluidPage(
  page_sidebar(
    sidebar = sidebar(
      actionButton(inputId = "insert_extra_page", label = "insert extra page")
    ),
    # Main Page
    page_navbar(
      id = "main",
      nav_panel(
        title = "test_1",
        popover(
          trigger = actionButton(
            "btn_pop", 
            "Click here for popover"
          ),
          "Popover message",
          title = "Popover title"
        ),
      ),
    )
  )
)

server <- function(input, output, session) {
  observeEvent(input$insert_extra_page, {
    nav_insert(
      id = "main",
      nav = nav_panel(
        title = "test_2",
        tagList(
          popover(
            trigger = actionButton(
              "btn_pop", 
              "Click here for popover"
            ),
            "Popover message",
            title = "Popover title"
          ),
        )
      )
    )
  })
}
shinyApp(ui, server)

Session Info






Session Info
 setting  value
 version  R version 4.3.3 (2024-02-29 ucrt)
 os       Windows 11 x64 (build 22631)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United Kingdom.utf8
 ctype    English_United Kingdom.utf8
 tz       Europe/Brussels
 date     2024-03-20
 rstudio  2023.12.1+402 Ocean Storm (desktop)
 pandoc   NA

Packages
 package     * version    date (UTC) lib source
 bslib       * 0.6.1.9001 2024-03-20 [1] Github (rstudio/bslib@8774166)
 cachem        1.0.8      2023-05-01 [1] CRAN (R 4.3.2)
 callr         3.7.3      2022-11-02 [1] CRAN (R 4.3.2)
 cli           3.6.2      2023-12-11 [1] CRAN (R 4.3.2)
 curl          5.2.0      2023-12-08 [1] CRAN (R 4.3.2)
 desc          1.4.3      2023-12-10 [1] CRAN (R 4.3.2)
 devtools      2.4.5      2022-10-11 [1] CRAN (R 4.3.2)
 digest        0.6.35     2024-03-11 [1] CRAN (R 4.3.3)
 ellipsis      0.3.2      2021-04-29 [1] CRAN (R 4.3.2)
 fansi         1.0.6      2023-12-08 [1] CRAN (R 4.3.2)
 fastmap       1.1.1      2023-02-24 [1] CRAN (R 4.3.2)
 fs            1.6.3      2023-07-20 [1] CRAN (R 4.3.2)
 glue          1.7.0      2024-01-09 [1] CRAN (R 4.3.2)
 htmltools     0.5.7.9000 2024-03-20 [1] Github (rstudio/htmltools@30d13a1)
 htmlwidgets   1.6.4      2023-12-06 [1] CRAN (R 4.3.2)
 httpuv        1.6.14     2024-01-26 [1] CRAN (R 4.3.2)
 jquerylib     0.1.4      2021-04-26 [1] CRAN (R 4.3.2)
 jsonlite      1.8.8      2023-12-04 [1] CRAN (R 4.3.2)
 later         1.3.2      2023-12-06 [1] CRAN (R 4.3.2)
 lifecycle     1.0.4      2023-11-07 [1] CRAN (R 4.3.2)
 magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.3.2)
 memoise       2.0.1      2021-11-26 [1] CRAN (R 4.3.2)
 mime          0.12       2021-09-28 [1] CRAN (R 4.3.1)
 miniUI        0.1.1.1    2018-05-18 [1] CRAN (R 4.3.2)
 pillar        1.9.0      2023-03-22 [1] CRAN (R 4.3.2)
 pkgbuild      1.4.3      2023-12-10 [1] CRAN (R 4.3.2)
 pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.3.2)
 pkgload       1.3.4      2024-01-16 [1] RSPM (R 4.3.0)
 processx      3.8.3      2023-12-10 [1] CRAN (R 4.3.2)
 profvis       0.3.8      2023-05-02 [1] CRAN (R 4.3.2)
 promises      1.2.1      2023-08-10 [1] CRAN (R 4.3.2)
 ps            1.7.6      2024-01-18 [1] RSPM (R 4.3.0)
 purrr         1.0.2      2023-08-10 [1] CRAN (R 4.3.2)
 R6            2.5.1      2021-08-19 [1] CRAN (R 4.3.2)
 Rcpp          1.0.12     2024-01-09 [1] CRAN (R 4.3.2)
 remotes       2.4.2.1    2023-07-18 [1] CRAN (R 4.3.2)
 rlang         1.1.3      2024-01-10 [1] CRAN (R 4.3.2)
 rstudioapi    0.15.0     2023-07-07 [1] CRAN (R 4.3.2)
 sass          0.4.9.9000 2024-03-20 [1] Github (rstudio/sass@e58a619)
 sessioninfo   1.2.2      2021-12-06 [1] CRAN (R 4.3.2)
 shiny       * 1.8.0      2023-11-17 [1] CRAN (R 4.3.2)
 stringi       1.8.3      2023-12-11 [1] CRAN (R 4.3.2)
 stringr       1.5.1      2023-11-14 [1] RSPM (R 4.3.0)
 tibble        3.2.1      2023-03-20 [1] CRAN (R 4.3.2)
 urlchecker    1.0.1      2021-11-30 [1] CRAN (R 4.3.2)
 usethis       2.2.3      2024-02-19 [1] RSPM (R 4.3.0)
 utf8          1.2.4      2023-10-22 [1] CRAN (R 4.3.2)
 vctrs         0.6.5      2023-12-01 [1] CRAN (R 4.3.2)
 xtable        1.8-4      2019-04-21 [1] CRAN (R 4.3.2)


cpsievert commented 6 months ago

Thanks! Here is a more minimal example with both popover() and tooltip().

BTW, your example has an additional problem of multiple actionButton() with the same id ("btn_pop").

library(shiny)
library(bslib)

ui <- page_navbar(
  sidebar = list(
    actionButton("insert_popover", "Insert popover"),
    actionButton("insert_tooltip", "Insert tooltip")
  ),
  id = "navbar",
  nav_panel("Home", "Home page")
)

server <- function(input, output, session) {
  observeEvent(input$insert_popover, {
    nav_insert(
      id = "navbar",
      nav = nav_panel(
        "Popover",
          popover(
            trigger = actionButton(
              "show_popover", 
              "Click here for popover"
            ),
            "Popover message",
            title = "Popover title"
          )
      )
    )
  })

  observeEvent(input$insert_tooltip, {
    nav_insert(
      id = "navbar",
      nav = nav_panel(
        "Tooltip",
        tooltip(
          trigger = actionButton(
            "show_tooltip", 
            "Click here for tooltip"
          ),
          "Tooltip message"
        )
      )
    )
  })
}
shinyApp(ui, server)
github-actions[bot] commented 4 months ago

This issue has been automatically locked. If you have found a related problem, please open a new issue (with a reproducible example or feature request) and link to this issue. :raising_hand: Need help? Connect with us on Discord or Posit Community.