簡體   English   中英

如何在被編織為 HTML 的 R markdown 文檔中嵌入推文?

[英]How to embed tweets in R markdown documents being knit to HTML?

使用blogdown R 包和 Hugo 短blogdown文嵌入到博客文章中是相當容易的,如https://bookdown.org/yihui/blogdown/content.html 所述

我想將推文嵌入到一個獨立的 HTML 文檔中的 R 降價文檔中。 做這個的最好方式是什么? 看起來 Twitter 提供了一個嵌入推文功能,我可以交互地使用它來讓 HTML 嵌入推文,但我需要以編程方式執行此操作,給定推文 ID。

對於不想上 twitter 的人,該線程包括兩個包的建議。 twittrmdtwitterwidget 我能夠讓twittrmd工作如下:

安裝包

這是困難的部分,因為 CRAN webshot2庫與我的 R 環境不兼容。

devtools::install_github("gadenbuie/tweetrmd")

# necessary if your output type is not html (as far as I can tell)
devtools::install_github("rstudio/webshot2")

# this is a webshot2 requirement
install.packages("magick")

使用包

使用這些軟件包,您可以通過以下方式捕獲屏幕截圖

library(twittrmd)
include_tweet("https://twitter.com/nomadj1s/status/1294390352904966151")

如果您的輸出類型不是 html,則tweetrmd將呈現為 png 或 pdf。 無論如何,我認為你只能在編織時看到推文。

github上提供了更多信息,包括從用戶名和 tweet_id 構建 twitter url 的幫助函數以及有關如何使用memoise保留推文副本的想法,以防它從 twitter 中刪除。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM