1

I haven't found any information in documentation of shinyBS and on the google/SO about how to use trigger = 'manual' on, for example, addPopover of shinyBS. I thought this would be the way to add a tooltip to a disabled button. (I dont want to do it with div'ving the button and giving title to div. Also would be nice if someone has a way to add tooltips reactively to shiny apps

Florian
  • 24,425
  • 4
  • 49
  • 80
vladli
  • 1,454
  • 2
  • 16
  • 40
  • 1
    Can u please provide a reproducible example please. I am sure I can give u a hand – Pork Chop Jul 06 '17 at 11:11
  • @PorkChop There is an answer to the question with sufficiable example. Sry i couldn't answer earlier. The thing i'm trying to do is adding a popover over `disabled` button that shows up on `hover`ing it with mouse, and deleting it when the button becomes active. – vladli Jul 07 '17 at 11:56

2 Answers2

2

If you want to use trigger = manual on the popover, then you need to define a script to toggle the popover, e.g. with jQuery:

library(shiny)
library(shinyjs)
library(shinyBS)


ui <-shinyUI(fluidPage(useShinyjs(),
                       # press this button to trigger the popover
                       actionButton("addPopover", "Add Popover"),
                       
                       # a disabled button
                       disabled(actionButton("disabledButton", "This button is disabled")),
                       
                       # the popover to appear over the disabled button
                       bsPopover("disabledButton", "Popover", "Some text", trigger="manual"),
                       
                       # the script to trigger the popover
                       uiOutput("trigger")))


server <- shinyServer(function(input,output, session){
  
  # on checkbox selection, disable button and trigger the popover
  output$trigger <- renderUI({
    input$addPopover
    tags$script("$('#disabledButton').popover('toggle');")
  })
})

shinyApp(ui,server)
shosaco
  • 5,915
  • 1
  • 30
  • 48
  • That's a nice way of doing it, thanks. Unfortunately, I'm don't know anything in jQuery. Could you give me a hint about how do I do it so the `actionButton`, that's being currently disabled, shows a popover on a hover? In my app I tried to do something like this: `if(condition == TRUE) { shinyjs::disable(buttonId); addTooltip(session, id = 'buttonId', title = paste0('This button is currently disabled.')`, didnt work out quite well – vladli Jul 07 '17 at 11:54
  • updated my solution to the version including "no jquery"-solution... strange why `addPopover` doesn't work... – shosaco Jul 07 '17 at 12:07
  • Doesn't work for me either, even with `bsTooltip`. It shows a tooltip if you move a mouse fast enough after un-ckecking the ckeckbox though. I didnt say I dont like jquery solution, it's just I need popover to be shown on `hover`, not on button click. But usual `hover` doesn't work with disabled buttons, that's why I thought about `manial` option. – vladli Jul 07 '17 at 12:15
  • It should work fine. The toolitp is only shown after *activating* the checkbox, i.e. disabling the button. It is *not* shown when button is enabled - that is what you wanted, right? What's your `packageVersion("shinyBS")`? I added a picture. – shosaco Jul 07 '17 at 12:21
  • Hmm, it doesn't work for me on Chrome/IE/Opera. shinyBS version is `"shinyBS 0.61 2015-03-30"` – vladli Jul 07 '17 at 12:57
  • That approach that you've used in the second solution was the first thing i tried when I needed to add tooltip. It also didnt work with `addTooltip`, `addPopover`, `popify` and other things `shinyBS` provides to make this kinds of pop-ups. – vladli Jul 07 '17 at 13:37
  • Then there is a problem on your architecture I'm afraid, because it works fine on my side :-s – shosaco Jul 07 '17 at 13:48
  • I tried it both on windows and mac, still not working. How do you run it? What are your machine / browser? – vladli Jul 07 '17 at 14:01
  • It did not work with downloadButton(...) for me. – PhilippPro Mar 17 '21 at 12:18
  • Just re-testet, first one works for me, shinyBS 0.61, shinyjs 2.0.0 – shosaco Mar 19 '21 at 09:38
  • The second one seems to have changes in the last 4 years, so I removed that. – shosaco Mar 19 '21 at 09:44
-2

Since shosaco's solution didnt work for me, I got it to work this way:

if (input$disable) { 
  addCssClass("buttonId", "disabled")
  bsTooltip("buttonId", "This button is currently disabled.")
} else {
  bsTooltip("buttonId", "")
  removeCssClass("buttonId", "disabled")
}
observeEvent(input$buttonId, {
    if (!input$disable) {
      output$text <- renderText("Bla")
    } else {
      output$text <- renderText(NULL)
    }
vladli
  • 1,454
  • 2
  • 16
  • 40