Skip to content

Instantly share code, notes, and snippets.

@yonicd
Created January 22, 2019 14:42
Show Gist options
  • Save yonicd/ba049bdf1db57de8adc3b3abdbc789a1 to your computer and use it in GitHub Desktop.
Save yonicd/ba049bdf1db57de8adc3b3abdbc789a1 to your computer and use it in GitHub Desktop.
slick rtweet
library(rtweet)
library(slickR) # remotes::install_github('metrumresearchgroup/slickR')
tweets <- rtweet::search_tweets("#rstats", n = 5, include_rts = FALSE)
# https://github.com/mkearney/rtweet/pull/305/files
tweet_embed <- function(screen_name,status_id,...){
stem <- 'https://publish.twitter.com/oembed'
l <- list(...)
l$url <- sprintf('https://twitter.com/%s/status/%s',screen_name,status_id)
lpaste <- paste(names(l),as.character(l)%>%tolower(),sep='=',collapse = '&')
URI <- paste(stem,lpaste,sep = '?')
ret <- URI%>%httr::GET()%>%httr::content()
ret$html
}
ui <- shiny::fluidPage(
shiny::titlePanel("Tweet embed example"),
shiny::sidebarLayout(
shiny::sidebarPanel(
shiny::sliderInput(inputId = "slide",label = "tweets in slick",min = 1,max = nrow(tweets),value = nrow(tweets),step = 1)
),
shiny::mainPanel(
slickR::slickROutput('slick'),
)
)
)
server <- function(input, output) {
output$slick <- slickR::renderSlickR({
twe <- tweets %>%
dplyr::slice(1:input$slide) %>%
dplyr::select(screen_name, status_id) %>%
purrr::pmap_chr(tweet_embed)
slickR::slickR(
obj = twe,
slideType = 'iframe',
slickOpts = list(
autoplay=TRUE,
vertical = TRUE,
adaptiveHeight = TRUE,
autoplaySpeed = 300,
speed = 800),
width = '20%',
height = '50%')
})
}
# Run the application
shiny::shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment