tiktokrmd
Embed TikTok videos in R Markdown things!
Installation
You can install the released version of tictokrmd from GitHub:
remotes::install_github("gadenbuie/tiktokrmd")
How to TikTok in R Markdown
Example
library(tiktokrmd)
tt_url <- "https://www.tiktok.com/@aquickspoonful/video/6890681375431691526"
tt <- tiktok_embed(tt_url)
## # in R Markdown, just print the object to embed it
## tt
# Or write a plain markdown version
tiktok_md(tt)
#> [1] "![[#cake #cakes #dontmixit #cakelover #cakelovers #dumpcake #food #tiktokfood #foodtiktok #easyrecipe #easyrecipes #peach #peaches #cinnamon #fyp](https://www.tiktok.com/@aquickspoonful/video/6890681375431691526) by [Sophia Wasu](https://www.tiktok.com/@aquickspoonful)](https://p16-sign-va.tiktokcdn.com/obj/tos-maliva-p-0068/00189a8b703343bd817a3ccaec240f71?x-expires=1610654400&x-signature=ExJZaEMAgxhyXydfgsqgZqU%2B8y8%3D)"
# Or as HTML without the full TikTok embedded player shenanigans
tiktok_html(tt, include_player = FALSE)
@aquickspoonful \#cake \#cakes \#dontmixit \#cakelover \#cakelovers \#dumpcake \#food \#tiktokfood \#foodtiktok \#easyrecipe \#easyrecipes \#peach \#peaches \#cinnamon \#fyp
♬ original sound - Sophia Wasu
⚠️ Previewing Locally ⚠️
TikTok’s embedding script only works when the page with the embedded video is being served. For some reason, it doesn’t seem to work when viewing a local file.
The easiest way around this is to use the Infinite Moon Reader addin
(or inf_mr()
) from xaringan to
render your R Markdown document. If you’re working on a blog post,
blogdown::serve_site()
probably works fine. In all cases, you’ll still
need to preview the rendered page in an external browser, like FireFox,
Chrome, or Safari.
Description
Embeds a TikTok video in an R Markdown document. In rich HTML formats, the
full TikTok video player is used. Note that the video will likely fail to
appear when previewing locally, unless you serve the document with something
like servr::httd()
. In limited HTML formats or non-HTML formats, the
TikTok content is rendered into an image with a link in markdown. Use the
helper functions listed below if you want to control the output.
Usage
tiktok_embed(url) tiktok_md(tt, ...) tiktok_html(tt, include_player = TRUE, ...)
Arguments
url |
A TikTok video URL |
tt |
A TikTok video URL or |
... |
Ignored |
include_player |
Include the TikTok embed JavaScript that builds the rich HTML player (and probably adds a considerable amount of user tracking) |
Value
tiktok_embed
: Returns the TikTok oEmbed API response. The returned
object has a knit_print()
method for automatic embedding in R Markdown.
tiktok_md
: A Markdown representation of the TikTok video, in the
format ![<title> by <author>](<thumbnail_image_url>)
tiktok_html
: The TikTok embedding HTML as an htmltools::tagList
Functions
-
tiktok_embed
: Embed a TikTok video in R Markdown, or return the oEmbed API response. -
tiktok_md
: Format the TikTok video url ortiktok_embed()
result as markdown -
tiktok_html
: Format the TikTok video url ortiktok_embed()
result as HTML