Context
I'm trying to have a tooltip popup show on click at the info icon, and hide on click at the icon itself or at any other place of the app. Pretty much as how the tooltips in the left panel of SO behave.
So far I've borrowed from this SO accepted answer to get the tooltip to show and hide on click of the info icon with data-trigger="click"
. However, I haven't been able to have it hidden also on click at any other place of the app.
I've tried with different combinations of data-trigger
types like hover click
and focus
, but these don't have the desired effect. I've also seen some SO answers (e.g., [1], [2], [3]) out of the specific Shiny context using some JS and jQuery, but I'm not skilled enough in any of the two languages to adapt the solutions to my need.
An MRE of my code so far
CSS file: style.css
.tooltip > .tooltip-inner {
pointer-events: none;
background-color: #2355b4;
color: #FFFFFF;
border: 1px solid #000000;
padding: 10px;
font-size: 25px;
font-style: italic;
text-align: justify;
margin-left: 0;
max-width: 1000px;
}
JS file: dynam.js
$(function () {
$('[data-toggle=tooltip]').tooltip()
})
R Shiny file: myApp.R
library(shiny)
ui <- function() {
fluidPage(
includeCSS("style.css"),
includeScript("dynam.js"),
br(),br(),
span(
"Text that might need further explanation",
span(
`data-toggle` = "tooltip",
`data-placement` = "right",
`data-trigger` = "click",
title = "Further explanation",
icon("info-circle")
)
)
)
}
server <- function(input, server, output, session) {}
shinyApp(ui = ui, server = server,
options = list(display.mode = "normal"),
enableBookmarking = "server")