【问题标题】:twitter bootstrap popovers for R shiny app - html is interpreted as text content - why?R 闪亮应用程序的 twitter 引导弹出框 - html 被解释为文本内容 - 为什么?
【发布时间】:2013-09-28 05:02:47
【问题描述】:

我想将 twitter 引导框架中的弹出框添加到闪亮的应用程序中。一切正常,除了 html: true 标签没有作用:

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 相同的代码(没有闪亮的部分)可以正常工作:

<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框架不是太熟悉,但是可能和shiny包含的版本有关吗?

【问题讨论】:

    标签: javascript r twitter-bootstrap shiny


    【解决方案1】:

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

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

    并在您的脚本中使用以下内容

    tags$head(tags$script(HTML(yourStr)))
    

    【讨论】:

      猜你喜欢
      • 2019-05-09
      • 2019-09-08
      • 1970-01-01
      • 2019-03-18
      • 1970-01-01
      • 1970-01-01
      • 2018-09-16
      • 1970-01-01
      • 2014-04-02
      相关资源
      最近更新 更多