在Shiny上嵌入Twitter时间线时出错

时间:2015-01-11 10:14:34

标签: r twitter shiny

我正在尝试解决这个问题:

How can I embed a twitter timeline in a Shiny app

这是我的代码:

library(shiny)
runApp(list(ui = fluidPage(
  tags$head(tags$script('!function(d,s,id){var js,fjs=d.getElementsByTagName(s)    [0],p=/^http:/.test(d.location)?\'http\':\'https\';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");')),
  titlePanel(""),
  sidebarLayout(
    sidebarPanel()
    , mainPanel(
      a("BreakingNews",class="twitter-timeline",href = "https://twitter.com/BreakingNews", "data-widget-id"="553910163694821376")     
               )
               )
 )
, server = function(input, output, session){

}
)
)

我收到此错误:

Error in handlers$add(handler, key, tail) : Key / already in use

1 个答案:

答案 0 :(得分:0)

所以我调整了一下代码,至少错误就消失了。

library(shiny)
      shinyUI(fluidPage(
  tags$head(tags$script('!function(d,s,id){var js,fjs=d.getElementsByTagName(s)    [0],p=/^http:/.test(d.location)?\'http\':\'https\';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");')),
  titlePanel(""),
  sidebarLayout(
      sidebarPanel(),
      mainPanel(
      a("@ChannelNewsAsia",class="twitter-timeline",href="https://twitter.com/ChannelNewsAsia", "data-widget-id"=553910391399383040)     
               )
               )
 )
)

但现在屏幕只显示句柄名称,即@ChannelNewsAsia,点击后会将用户带到指定的链接。 ui上还没有出现时间线小工具