html - 我如何在 Shiny 的应用程序中嵌入 Twitter 时间轴?

标签 html r twitter shiny shinydashboard

很难将 Twitter 时间轴嵌入到 Shiny 的应用程序中。

试图遵循此代码

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("Soccer", class="twitter-timeline"
        , href = "https://twitter.com/pssGuy/timelines/524678699061641216"
        , "data-widget-id" = "524686407298596864")
    )
  )
)
, server = function(input, output, session){

}
)
)

但现在 Twitter 已经改变了他们生产小部件的方式,我无法弄清楚如何获取新的数据小部件 ID。对 HTML 或 JS 不太熟悉,因此不胜感激!

希望嵌入“https://twitter.com/CityOfBoston”的时间线

最佳答案

编辑以包括 OP 关于重新格式化为带有选项卡的 Shiny 仪表板页面的评论。 我认为您不再需要 data-widget-id 了。这会为我加载时间线。

library(shiny)
runApp(list(ui = dashboardPage(header=dashboardHeader(titleWidth=150,
                                title = "Title"),
                        sidebar=dashboardSidebar(width=150,
                                sidebarMenu(
                                        menuItem("Twitter Timeline", tabName="twittertimeline", icon=icon("globe")),
                                        menuItem("Empty Tab", tabName = "empty", icon=icon("info-circle"))
                                )
                        ),
                        body=dashboardBody(
                                tabItems(
                                        tabItem(tabName="twittertimeline",
                                                fluidRow(column(width=12,
                        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");')),
                         column(width=6, box(width=NULL, height=NULL,
                                        a("Tweets by @CityOfBoston", class="twitter-timeline"
                                                , href = "https://twitter.com/CityOfBoston"
                                         )
                                )
                        )
                ))),
tabItem(tabName="empty",
        fluidRow(column(width=12,
                        box(width=NULL,height=NULL)
                        )))

)))
                , server = function(input, output, session){

                }
        )
)

关于html - 我如何在 Shiny 的应用程序中嵌入 Twitter 时间轴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45257922/

相关文章:

r - 基于另一个 df 匹配的 df 子集 (R/R Studio)

mysql - 将推文 ID 存储为 BIGINT 是否安全?

html - 如何显示内联消息

html - 中间有双倍尺寸边框的 CSS 表格元素

javascript - 在列表文本装饰中的悬停文本上不起作用

r - 增加离散图例的中断

r - 无法在R上加载rJava

javascript - 类型错误:参数 url 必须是字符串,而不是对象

python - 中间用户在转发链中的作用

jquery - 包含 div 继承具有绝对位置的内部列表的宽度