Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to add popovers from the twitter bootstrap framework to a shiny app. Everything works fine, except that the html: true tag does not have an 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) just 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 too familiar with the bootstrap framework, but may it have to do with the version that is included by shiny?

like image 806
Mark Heckmann Avatar asked Oct 26 '25 14:10

Mark Heckmann


1 Answers

The tags enviroment carries out HTML escaping. In order to prevent this on your html string you need to mark 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 your script

tags$head(tags$script(HTML(yourStr)))
like image 186
jdharrison Avatar answered Oct 28 '25 02:10

jdharrison