TikTok in R!
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.
You can just update the remotes package as Garrick pointed out.
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/tiktokrmd@main") 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](https://i0.wp.com/images.squarespace-cdn.com/content/v1/58eef8846a4963e429687a4d/1611754542408-Y5EWNV263J8GKOGD0MNG/ke17ZwdGBToddI8pDm48kFFs_NIDX9j2mpzEO5QowjJ7gQa3H78H3Y0txjaiv_0fDoOvxcdMmMKkDsyUqMSsMWxHk725yiiHCCLfrh8O1z4YTzHvnKhyp6Da-NYroOW3ZGjoBKy3azqku80C789l0sXC7mwOJ02xjUw3zNLbr4d2uj08OFTyMDwr1ERRk_PSNwnjaWHcaMQRXpwn7x2MbA/Screen+Shot+2021-01-27+at+7.35.32+AM.png?w=578&ssl=1)
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!
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.