• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    R
  • License
    Other
  • Created almost 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Embed Tweets in R Markdown

tweetrmd

Easily embed Tweets anywhere R Markdown turns plain text into HTML.

Installation

You can install the released version of tweetrmd from GitHub:

# install.packages("devtools")
devtools::install_github("gadenbuie/tweetrmd")

Embed a Tweet

library(tweetrmd)
tweet_embed("https://twitter.com/alexpghayes/status/1211748406730706944")

anybody have experience embedding tweets into #rmarkdown documents *without using blogdown*?https://t.co/5kQUBh7j4g

— alex hayes (@alexpghayes) December 30, 2019

Or if you would rather use the screen name and status id.

tweet_embed(tweet_url("alexpghayes", "1211748406730706944"))

anybody have experience embedding tweets into #rmarkdown documents *without using blogdown*?https://t.co/5kQUBh7j4g

— alex hayes (@alexpghayes) December 30, 2019

In rich HTML outputs, the full embedded tweet is available and interactive. Here, in GitHub-flavored markdown, only the content of the tweet is seen.

Embed many tweets

If you have several tweets you would like to embed at once, you can use the following pattern to include add a vector of tweets to your document. This works well when you want to include a thread of tweets.

thread <- c(
  "https://twitter.com/grrrck/status/1333804309272621060",
  "https://twitter.com/grrrck/status/1333804487148855300", 
  "https://twitter.com/grrrck/status/1333805092152123394"
)

htmltools::tagList(
  lapply(thread, tweet_embed, plain = TRUE)
)

I've got a new work laptop! I'm going to try to track my setup process and the software and tools I install in this thread pic.twitter.com/9X2qvHB3no

— Garrick Aden-Buie (@grrrck) December 1, 2020

Step #1, wait... pic.twitter.com/3533LZZQBt

— Garrick Aden-Buie (@grrrck) December 1, 2020

Oh wow, I really jumped the gun on this thread pic.twitter.com/XpbzLTzStf

— Garrick Aden-Buie (@grrrck) December 1, 2020

(Note that I used plain = TRUE to embed each tweet as markdown.)

Take a screenshot of a tweet

Screenshots are automatically embedded in R Markdown documents, or you can save the screenshot as a .png or .pdf file. Uses the rstudio/webshot2 package.

tweet_screenshot(tweet_url("alexpghayes", "1211748406730706944"))

Just include a tweet in any R Markdown output format

When you want to include a tweet in multiple R Markdown formats, you can use include_tweet(). It’s like knitr::include_graphics() but for tweets. The function will automatically include the tweet as HTML in HTML outputs, or as a screenshot in all others.

```{r tweet-from-dsquintana}
include_tweet("https://twitter.com/dsquintana/status/1275705042385940480")
```

{bookdown} folks: I'm trying to knit a PDF version of a HTML book that contains HTML elements (embedded tweets).

Is there a way to automatically take a screenshot of embedded tweets for PDF output?

Using the {webshot} package + PhantomJS didn't work...#Rstats

— Dan Quintana (@dsquintana) June 24, 2020

Customize tweet appearance

Twitter’s oembed API provides a number of options, all of which are made available for customization in tweet_embed() and tweet_screenshot().

tweet_screenshot(
  tweet_url("alexpghayes", "1211748406730706944"),
  maxwidth = 300,
  hide_media = TRUE,
  theme = "dark"
)

Embed without tracking

You can use tweetrmd to embed tweets in your documents and outputs without including Twitter JavaScript or tracking. The easiest way is to set plain = TRUE in include_tweet(). This will insert minimal HTML for web outputs or convert the tweet text to markdown for non-web outputs.

include_tweet(
  "https://twitter.com/dsquintana/status/1275705042385940480",
  plain = TRUE
)
```{=html}
<blockquote class="twitter-tweet" data-width="550" data-lang="en" data-dnt="true" data-theme="light"><p lang="en" dir="ltr">{bookdown} folks: I&#39;m trying to knit a PDF version of a HTML book that contains HTML elements (embedded tweets). <br><br>Is there a way to automatically take a screenshot of embedded tweets for PDF output? <br><br>Using the {webshot} package + PhantomJS didn&#39;t work...<a href="https://twitter.com/hashtag/Rstats?src=hash&amp;ref_src=twsrc%5Etfw">#Rstats</a></p>&mdash; Dan Quintana (@dsquintana) <a href="https://twitter.com/dsquintana/status/1275705042385940480?ref_src=twsrc%5Etfw">June 24, 2020</a></blockquote>

```

Alternatively, you can choose to use tweet_screenshot() or tweet_markdown() to embed all tweets in your documents.

Caching tweets with memoization

Tweets are often deleted and re-running tweet_embed() or tweet_screenshot() may fail or overwrite a previous screenshot of a tweet. To avoid this, you can use the memoise package.

library(memoise)

tweet_cached <- memoise(tweet_embed, cache = cache_filesystem('.tweets'))
tweet_shot_cached <- memoise(tweet_screenshot, cache = cache_filesystem('.tweets'))

*When memoising tweet_screenshot() you need to manually save the file to a specific location. In the future my goal is for this to be automatic.


Note: When using tweet_embed(), you may need to add the following line to your YAML header for strict markdown output formats.

always_allow_html: true

More Repositories

1

tidyexplain

🤹‍♀ Animations of tidyverse verbs using R, the tidyverse, and gganimate
R
758
star
2

rsthemes

🔮 Full RStudio IDE and Syntax Themes
SCSS
504
star
3

regexplain

🔍 An RStudio addin slash regex utility belt
R
476
star
4

xaringanthemer

😎 Give your xaringan slides some style
R
437
star
5

xaringanExtra

🎡 A playground of enhancements and extensions for xaringan slides.
JavaScript
433
star
6

ggpomological

🍑 Pomological plot theme for ggplot2
R
325
star
7

countdown

⏲ countdown timer for R Markdown slides and HTML docs
JavaScript
148
star
8

epoxy

Extra-strength glue engines for R Markdown and Quarto
R
146
star
9

cleanrmd

📄✨Clean Class-Less R Markdown HTML Documents
CSS
128
star
10

tweet-conf-dash

A shiny twitter conference dashboard
CSS
121
star
11

shrtcts

Make Anything an RStudio Shortcut
R
103
star
12

ggweekly

🗓 🖨 Easy, printable, custom calendars and week planners
R
101
star
13

gentle-ggplot2

📊 A Gentle Guide to the Grammar of Graphics with ggplot2
HTML
83
star
14

grkstyle

A Tidy R Code Style
R
81
star
15

metathis

ℹ️ <meta> tags and social media cards for R-made web things
R
62
star
16

js4shiny

Companion Package for JavaScript for Shiny Users
R
53
star
17

mueller-report

The ██redacted Mueller Report
R
47
star
18

shinyComponents

📝✨ Shiny Components in R Markdown
R
44
star
19

trump-tweet-time

🎮 An 8-bit Trump tweet guessing game for your "executive time"
R
36
star
20

starwarsdb

Relational Data from the Star Wars API for Learning and Teaching
R
35
star
21

covid19-florida

Florida COVID19 Data parsed from Florida DOH Dashboard and PDF reports
HTML
32
star
22

rsconf_tweets

rstudio::conf 2018 tweet explorer and FOMO reducer
R
30
star
23

status

HTML
29
star
24

ermoji

🤷‍♂️ RStudio Addin to Search and Copy Emoji
R
26
star
25

lorem

Generate Lorem Ipsum Text
R
26
star
26

shinyThings

Reusable Shiny Modules and Other Shiny Things
R
25
star
27

trug-ggplot2

📊 Slides for presentation on ggplot2 at Tampa R Users Meetup (Jan 2018)
R
23
star
28

yule-rstudio

⛄️🎄🖥 A Holiday Theme for RStudio
22
star
29

snippets

My snippets for RStudio (or elsewhere)
Vim Snippet
21
star
30

slides

HTML
20
star
31

tiktokrmd

Embed TikTok Videos in R Markdown
R
18
star
32

xaringan-logo

xaringan template with logo on all slides
HTML
17
star
33

tweets-of-the-year

R
16
star
34

xaringan2powerpoint

a snarky powerpoint from xaringan demo
HTML
16
star
35

drake-intro

Reproducible Data Workflows with Drake
R
14
star
36

getcitations

R script to extract pandoc citations from markdown text and create local .bib file from a master BibTeX library.
R
14
star
37

applause

👏 Zero-Configuration Applause/Claps/Kudos Button for R Markdown and Shiny apps
R
14
star
38

tidyjs-r

Tidy Data with JavaScript and tidy.js
R
14
star
39

sprinkles

Utility CSS and JavaScript for R Markdown
JavaScript
14
star
40

rstudio-global-2021-calendar

Build your talk calendar for rstudio::global(2021)
R
13
star
41

garrickadenbuie-com

My personal website
HTML
13
star
42

intro-to-git-for-scientists

Intro to git for scientists and other regular people
TeX
12
star
43

de-iris-my-repos

It's time to move on from iris
R
12
star
44

repromonkey

🐒 A Reproducibility Chaos Monkey
R
12
star
45

oceanic-eighties

👨‍🎤 Oceanic Eighties Theme for RStudio
11
star
46

js4shiny-frappeCharts

Building an HTML Widget, a demonstration
HTML
11
star
47

synamyn

Synonyms! An RStudio addin interface for ropenscilabs/syn
R
10
star
48

gathertweet

Commandline utility for quick {rtweet} tweet gathering
R
9
star
49

r-colors-css

A utility CSS stylesheet with R's color names
HTML
8
star
50

rsprefs

Manage and Sync Your RStudio Preferences
R
8
star
51

js4shiny-drumkit

HTML
8
star
52

branchMover

An RStudio Addin to Help Move the Default Branch of Your GitHub Repos
R
8
star
53

rstudio-ide-tips-demo

Companion to rstudio-ide-tips
R
7
star
54

gadenbuie

7
star
55

mctestanalysis

📚 Apps and reports for multiple-choice test analysis in R with Shiny
R
6
star
56

rstudio-ide-tips

Slides for RStudio IDE Tips
JavaScript
6
star
57

rstudioAddinFriend

RStudio addin to help you build RStudio addins
R
5
star
58

drake-rstudio-jobs-example

R
5
star
59

extra-awesome-xaringan

R
4
star
60

pagedown-cheatsheet

JavaScript
4
star
61

docker-rstudio-keras

🐳 RStudio + tidyverse + keras (cpu)
Dockerfile
4
star
62

positron-plus-1-e

A Positron extension pack for dev and data science.
4
star
63

rstatsnyc-2018-tweets

Tweets from #rstatsnyc -- remix of rsconf tweet shiny app
R
3
star
64

ten-thousand-functions

Ten Thousand Reasons to Love Functions
CSS
3
star
65

msglooker

A Shiny App to View And Export Outlook Messages
R
3
star
66

crantrack

Hourly snapshots of CRAN's incoming packages folder
R
3
star
67

fwiffer

📏✨ Fixed width file definitions made easy
R
3
star
68

xaringan-club

A place to talk about xaringan
HTML
3
star
69

js4shiny-workshop-webpage

HTML
3
star
70

rstudioconf-notes

HTML
2
star
71

rocker-verse-metaflow

rocker/verse + {metaflow}
Dockerfile
2
star
72

nonlinear-opt-notes

Class notes for Nonlinear Optimization and Game Theory at USF, Spring 2016
2
star
73

rstats-tweets

R
2
star
74

alix

Warn About Accessibility Issues in HTML Documents and Apps
R
2
star
75

quarto-partials

Partial content templates for Quarto
Lua
1
star
76

resume

HTML
1
star
77

podcasts

R-based podcast catcher
R
1
star
78

ms-render-ui-delay

R
1
star
79

aws-p2-setup

My AWS EC2 p2 instance setup with nvidia-docker
Shell
1
star
80

usf-boot-camp-R

Slides and materials for R sessions at USF Code & Data Boot Camp 2014
R
1
star
81

xaringan-line-focus

HTML
1
star
82

rmedicine-2024-bslib

Next Generation Shiny Apps with bslib
R
1
star
83

revealjs-text-resizer

Resize text on quarto slides
HTML
1
star
84

quarto-reprex-listing-chomp

EJS
1
star
85

docker-shinycannon

Dockerfile
1
star
86

speedDate

Quick Date Format Strings for strftime
R
1
star
87

quarto-tachyons

Tachyons Utility CSS for Quarto
CSS
1
star