I would like to create a popover/tooltip in my Shiny app that appears right away when the users switches to the tab that contains a data table that the popover is attached to. With the shinybs
package, I can create a popover that appear on click or hover, but I would like it to appear without needing to hover or click. My guess is that this could be achieved with the trigger = "manual"
option, but I don't know how to define a manual trigger. I'm not wedded to shinybs
; any other solution that can achieve the desired results is equally appreciated.
Ideally I would also like the popover to be placed such that it points to a particular row. I have previously used the rowCallback = JS(rowCallback)
parameter along with the shinyjs
package in data tables to get hover-over tooltips for individual rows. I don't know JavaScript; so I have no idea whether this could be modified such that the tooltip appears without hovering.
In any case, I also need an option to close the popover/tooltip. I'd really appreciate your help.
Here is a minimal example with a shinybs popover with a click trigger (not what I need):
library(shiny)
library(shinyBS)
library(DT)
data <- as.data.frame(rbind(c(1,2,3), c(4,5,6)))
colnames(data) <- c("Var1", "Var2", "Var3")
ui <- navbarPage(
title = "Title", id = "navbar",
tabsetPanel(id="tabs",
tabPanel(value = "tab1", title = "Tab1",
actionButton("action1", "Switch tabs")
),
)
)
server <- function(input, output, session) {
observeEvent(input$action1, {
insertTab(inputId = "tabs", target = "tab1", select=T,
tabPanel(value = "tab2", title = "Tab2",
dataTableOutput("table1"),
bsPopover(id="table1", title="A popover",
placement = "bottom", trigger = "click")
)
)
})
output$table1 <- renderDataTable({
datatable(data)
})
}
shinyApp(ui, server)