R/radio_tool_tip.R

Defines functions radio_tool_tip

Documented in radio_tool_tip

#' @title Adaptation of bsToolTip for radio buttons
#' @description TO ADD
#' @description This is a new line ...
#' @details What's this?
#' @export

radio_tool_tip <- function(id, choice, title, placement="bottom", trigger="hover", options=NULL){
  
  options = shinyBS:::buildTooltipOrPopoverOptionsList(title, placement, trigger, options)
  options = paste0("{'", paste(names(options), options, sep="': '", collapse="', '"), "'}")
  bsTag <- shiny::tags$script(shiny::HTML(paste0("
                                                 $(document).ready(function() {
                                                 setTimeout(function() {
                                                 $('input', $('#", id, "')).each(function(){
                                                 if(this.getAttribute('value') == '", choice, "') {
                                                 opts = $.extend(", options, ", {html: true});
                                                 $(this.parentElement).tooltip('destroy');
                                                 $(this.parentElement).tooltip(opts);
                                                 }
                                                 })
                                                 }, 500)
                                                 });
                                                 ")))
  htmltools::attachDependencies(bsTag, shinyBS:::shinyBSDep)
}
aidanmacnamara/epiChoose documentation built on Dec. 26, 2021, 3:13 a.m.