Below is a quick tutorial showing how to use the tiktokrmd package to display TikTok videos in .Rmd files and then serve them up on GitHub pages.
Late last week, Garrick Aden-Buie announced a new package that allows us to embed TikTok videos into R Markdown files. The package is called
tiktokrmd and can be found here. It should also be noted that Garrick, has a number of other fun samples and packages on his website, that I highly encourage y’all to check out.
Install the Package
Installing the package is straight forward through the
install_github() function in the
remotes package. This happened to be the first new package I downloaded from GitHub on a repo that was created since the default branch was named
main, so I encountered the need to employ one of two techniques below.
You can specify the branch as @main as I mentioned in a tweet.
#1) Update remotes to find the default branch #install.packages("remotes") #library(remotes) #remotes::install_github("gadenbuie/tiktokrmd") #2) Or if you have the remotes package installed and don't want to or can't re-install, you can just specify the branch #remotes::install_github("gadenbuie/[email protected]") library(tiktokrmd)
Embed your favorite TikTok video
This is probably the easiest tutorial I’ve written, just because of how simple Garrick has made his package. As per the instructions on his GitHub repo, simply set a variable to the TikTok video URL, pass it through the
tiktok_embed() function to display the embedded video.
For my example, I am including my favorite data TikTok by Chelsea Parlett. I also highly encourage y’all to check out her videos!
tt_url <- "https://www.tiktok.com/@chelseaparlettpelleriti/video/6811647290709757189" tt <- tiktok_embed(tt_url) tt
You can see the hosted .Rmd html output with an embedded TikTok video here!
Knit to HTML and host online
In the repo, Garrick points out that the html file needs to be hosted somewhere to fully display the video. Luckily GitHub pages has us covered.
Just follow the steps in my previous blog here to host your html, .Rmd output on GitHub pages.