@@ -3,7 +3,6 @@ library(grid)
33library(sdcMicro )
44library(rhandsontable )
55library(haven )
6- library(shinyBS )
76library(data.table )
87
98if (! getShinyOption(" sdcAppInvoked" , FALSE )) {# ## Beginning required code for deployment
@@ -233,6 +232,40 @@ summaryfn <- function(x) {
233232 vv
234233}
235234
235+ # to get rid of the shinyBS dependency
236+ tipify <- function (el , title , placement = " bottom" , trigger = " hover" , options = NULL ) {
237+ # generate a unique ID for the wrapper element and wrap element in span-tag
238+ wrapper_id <- paste0(" tip-" , round(runif(1 , 1e9 , 9e9 )), " -" , as.integer(Sys.time()))
239+ wrapped_el <- tags $ span(id = wrapper_id , el )
240+
241+ # define the JS options, forcing html: true allows to render inline-html code
242+ js_options <- list (
243+ html = TRUE
244+ )
245+ if (! is.null(options )) {
246+ js_options <- c(js_options , options )
247+ }
248+
249+ # add req. attributes
250+ wrapped_el <- htmltools :: tagAppendAttributes(
251+ wrapped_el ,
252+ " data-toggle" = " tooltip" ,
253+ " data-placement" = placement ,
254+ " data-trigger" = trigger
255+ )
256+
257+ # the attribute should be treated as html-content
258+ wrapped_el $ attribs $ title <- htmltools :: HTML(title )
259+
260+ # the js-script to initialize the tooltip using the generated id
261+ init_script <- tags $ script(HTML(paste0(
262+ " $(document).ready(function() { $('#" , wrapper_id , " ').tooltip(" ,
263+ jsonlite :: toJSON(js_options , auto_unbox = TRUE ),
264+ " );});"
265+ )))
266+ return (tagList(wrapped_el , init_script ))
267+ }
268+
236269# global, reactive data-structure
237270data(testdata , envir = .GlobalEnv )
238271data(testdata2 , envir = .GlobalEnv )
0 commit comments