How can i embed a twitter timeline in a shiny app?

前端 未结 1 760
生来不讨喜
生来不讨喜 2021-02-06 18:30

Having difficulty embedding a twitter timeline into a shiny app.

tried to follow this code

library(shiny)
runApp(list(ui = fluidPage(
  tags$head(tags$         


        
1条回答
  •  不思量自难忘°
    2021-02-06 19:01

    Edited to include OP comments on re-formatting as a shiny dashboard page with tabs. I don't think you need the data-widget-id anymore. 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){
    
                    }
            )
    )
    

    0 讨论(0)
提交回复
热议问题