Twitter bootstrap popovers for R shiny app - html interpreted as text content - why?

I want to add popovers from twitter bootstrap framework to a brilliant app. Everything works fine, except that the html: true tag has no effect:

 shinyUI(pageWithSidebar( headerPanel("Header"), sidebarPanel( actionButton("btn-1", "Go!") ), mainPanel( tags$head( tags$script(' $(document).ready(function(){ $("#btn-1") .popover({html: true, title: "Button 1", content: "<h1>Press</h1> for some action", trigger: "hover" }); }); ') ) ) )) 

enter image description here

The same code as pure HTML / JS (without the shiny part) works fine:

 <script> $(document).ready(function(){ $("#btn-1") .popover({html: true, title: "Button 1", content: "<h1>Press</h1> for some action", trigger: "hover", delay: {show: 100, hide: 100} }); }); </script> <button id="btn-1" type="submit" class="btn">Submit</button> 

enter image description here

Any ideas? I am not very familiar with the base of boot files, but can this be related to the version that is included shiny?

+3
source share
1 answer

The tags environment runs HTML escaping. To prevent this from happening on your html line, you need to tag it with HTML .

 yourStr <- '$(document).ready(function(){ $("#btn-1") .popover({html: true, title: "Button 1", content: "<h1>Press</h1> for some action", trigger: "hover" }); }); ' 

and use the following in a script

 tags$head(tags$script(HTML(yourStr))) 
+4
source

Source: https://habr.com/ru/post/1238940/


All Articles