Last active
January 22, 2019 14:29
-
-
Save gadenbuie/218898f4db2742a47da010744230d3d7 to your computer and use it in GitHub Desktop.
Tweet embed example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(dplyr) | |
library(rtweet) | |
tweets <- 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 <- fluidPage( | |
titlePanel("Tweet embed example"), | |
sidebarLayout( | |
sidebarPanel( | |
selectInput("status_id", "Tweet By", choices = setNames( | |
tweets$status_id, tweets$screen_name | |
)) | |
), | |
mainPanel( | |
uiOutput("tweet_oembed") | |
) | |
) | |
) | |
server <- function(input, output) { | |
output$tweet_oembed <- renderUI({ | |
tweets %>% | |
filter(status_id == input$status_id) %>% | |
select(screen_name, status_id) %>% | |
purrr::pmap_chr(tweet_embed) %>% | |
HTML() | |
}) | |
} | |
# Run the application | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
that script doesnt refresh in a reactive env.
here is my session info