Wikipedia Preview for R Markdown documents

Wikipedia Preview (developed by Wikimedia’s Inuka team) is so cool:

When readers navigate in and out of a webpage through interacting with several hyperlinks, they can easily lose context of what they were reading in the first place. Content sites would like their readers to read and engage with their content and understand it without having to get contextual information elsewhere. Wikipedia Preview can solve this problem for content providers by allowing readers to have concise and visual contextual information from Wikipedia within a content provider’s mobile properties - website or webapp.

The Page Previews feature on Wikipedia was created to solve the problem of context switching for desktop readers. This feature extends that functionality to external 3rd party sites.

(Text licensed under the Creative Commons Attribution-ShareAlike License)

wikipediapreview R package makes it easy to integrate this product in your R Markdown documents – whether you’re knitting HTML documents, distill articles, HTML vignettes in your package’s pkgdown-based online documentation, or posts like this in your blogdown-based website.

In fact, I’m using it right now! I started this post by initializing Wikipedia Preview – as easy as including the following snippet:

`r wikipediapreview::wp_init(use_unpkg = TRUE, with_styles = FALSE)`

I have use_unpkg = TRUE so I can use the JavaScript component that’s hosted on a CDN (rather that embedding the JS code in the post) and I have with_styles = FALSE because I have a custom CSS style which uses the Wikipedia “W” logo from Font Awesome.

For standalone, self-contained documents you would simply use:

`r wikipediapreview::wp_init()`

To learn more, please refer to the getting started guide.

Posted on:
April 9, 2022
2 minute read, 265 words
See Also:
Even faster matrix math in R on macOS with M1
Making Of: Session Tick visualization
Animation of optimization in torch