How can I embed twitter timeline in a shiny app?

The tricky part of embedding twitter timeline in a brilliant app.

tried this code

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

}
)
)

      

but now that twitter has changed the way the widgets are created, I cannot figure out how to get w the new data widget id. Not very familiar with HTML or JS, so any help would be appreciated!

hoping to embed the timeline " https://twitter.com/CityOfBoston "

+3


source to share


1 answer


Edited to include OP's comments to be reformatted as shiny tabbed dashboard page. I don't think you need data-widget-id

more. This loads the timeline for me.



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

                }
        )
)

      

+2


source







All Articles