TikTok in R!

[This article was first published on Blog - Little Miss Data, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

  1. You can just update the remotes package as Garrick pointed out.

  2. 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!

Screen Shot 2021-01-27 at 7.35.32 AM.png

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.


Thank You

Thank you for following along. The hosted output is here and the .Rmd file for this repo is here. If you replicate these steps, you can host TikTok videos in .Rmd on your own!

To leave a comment for the author, please follow the link and comment on their blog: Blog - Little Miss Data.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.