R boot app的twitter bootstrap popovers - html被解释为文本内容 - 为什么? [英] twitter bootstrap popovers for R shiny app - html is interpreted as text content - why?

查看:164
本文介绍了R boot app的twitter bootstrap popovers - html被解释为文本内容 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将twitter bootstrap框架中的popovers添加到一个闪亮的应用程序中。一切正常,除了
html:true 标签没有效果:

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"
                  });
          });   
      ')
    )
  )
))

与纯HTML / JS(没有闪亮部分)相同的代码工作正常:

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>

任何想法?我对bootstrap框架不太熟悉,但它可能与闪亮包含的版本有关吗?

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?

推荐答案

标签环境执行HTML转义。为了防止你的html字符串出现这种情况,你需要用 HTML 标记它。

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)))

这篇关于R boot app的twitter bootstrap popovers - html被解释为文本内容 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆