gadenbuie / tweetrmd

Embed Tweets in R Markdown
Other
102 stars 13 forks source link

Programmatically embed many tweets? #9

Closed alexpghayes closed 3 years ago

alexpghayes commented 3 years ago

Suppose I have five tweets. Is there an easy way to programmatically embed them all? Naive for looping didn't work for me.

gadenbuie commented 3 years ago

Have you tried something like this?

htmltools::tagList(
  lapply(tweet_urls, tweetrmd::tweet_embed)
)
alexpghayes commented 3 years ago

Will give that a shot. Can you explain why that would work/be necessary?

I would like to do this for both tweet_embed() and tweet_screenshot() if possible.

gadenbuie commented 3 years ago

Here's an example gist. tweet_embed() returns htmltools::HTML() with an html_dependency(), so the for loop probably didn't work because it needs to be printed. The htmltools::tagList() instead collects a list of html objects and outputs it all together at once.

I also demoed in that gist how to grab screenshots for a list of tweets. There a for loop would work, but essentially I'd recommend saving the screenshot to a specific file and then including those images in your markdown programmatically.

danmrc commented 3 years ago

Have you tried something like this?

htmltools::tagList(
  lapply(tweet_urls, tweetrmd::tweet_embed)
)

Came in the issues looking for some solution of this kind, this works great. I would add it to the documentation, because it is really useful

And thanks, the package is great !