shinyWidgets dropdownButton打开后tooltip无法消失的问题求助
I’ve run into this exact Bootstrap tooltip + dropdown conflict before! The issue is that your tooltip is set to trigger on hover, and when you click the dropdown button, your mouse is still positioned over it—so the tooltip doesn’t automatically hide. Setting hideDelay won’t help here because that only applies when the hover state ends. Instead, we need to manually trigger the tooltip to hide the moment the dropdown opens.
Here’s the modified working code:
library("shiny") library("shinyWidgets") shinyApp( ui = fluidPage( tags$head( tags$style('#dropdown-menu-MyDDM {left: 100px;}'), tags$script( HTML(" // Wait for the page to fully load $(document).ready(function() { // Listen for when the dropdown starts opening $('#MyDDM').on('show.bs.dropdown', function() { // Manually hide the tooltip attached to the button $(this).tooltip('hide'); }); }); ") ) ), dropdownButton( label = "CLICK", h5("HELLO"), icon = icon("gear"), inputId = "MyDDM", circle = TRUE, status = "info", size = "sm", tooltip = tooltipOptions(title = "Click to change plot"), width = "600px" ) ), server = function(input, output, session) { } )
How this works:
- We use Bootstrap’s built-in dropdown event
show.bs.dropdown, which fires immediately when the dropdown starts to open. - In the event handler, we target the dropdown button (
$(this)) and call Bootstrap tooltip’shidemethod to force the tooltip to disappear right as the dropdown expands. - I removed your original
tooltip: { hideDelay: 0 }from the style tag because that’s invalid CSS—tooltip configuration needs to be set viatooltipOptions()or JavaScript, not plain CSS.
If you want to tweak behavior further (like making the tooltip reappear when the dropdown closes), you could add a listener for the hide.bs.dropdown event to re-trigger the tooltip, but the above code should solve your immediate problem.
内容的提问来源于stack exchange,提问作者Mark

