Skip to content

Instantly share code, notes, and snippets.

@yonicd

yonicd/app.R

Created Jan 22, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.