Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
xaringanパッケージの内容をちょっとだけ
Search
Kazuhiro Maeda
October 11, 2019
Technology
0
980
xaringanパッケージの内容をちょっとだけ
Yakitori.R #02 (fukuoka.R #16)
Kazuhiro Maeda
October 11, 2019
Tweet
Share
More Decks by Kazuhiro Maeda
See All by Kazuhiro Maeda
積もってく会議メモをどうにかしたかった
kazutan
0
230
分析システムにR Markdownを組み込む
kazutan
0
450
Rに管理されてみる
kazutan
0
430
私とR、そしてキャリア
kazutan
2
3.4k
tubeplayR v1.0への道
kazutan
2
210
R, Git, Droneを使ってconfluenceへのKPI予測レポートを自動化した話
kazutan
2
570
週次KPIレポートをconfluenceへUpするためにやったこと
kazutan
1
1.3k
最近のRパッケージ開発事情
kazutan
0
340
Other Decks in Technology
See All in Technology
ソフトウェアエンジニアリングの知見を活かして データ基盤をいい感じにする on Snowflake [MIERUNE BBQ #10]
mtpooh
2
150
ギークの理想が7つ集まるエムスリーで夢を叶えよう - エムスリー株式会社
m3_engineering
1
260
推薦システムを本番導入する上で一番優先すべきだったこと~NewsPicks記事推薦機能の改善事例を元に~
morinota
0
130
How to Think Like a Performance Engineer
csswizardry
4
590
簡単に始めるSnowflakeの機械学習
nayuts
1
190
VPoEの視点から見た、ヘンリーがサーバーサイドKotlinを使う理由 / Why Server-side Kotlin 2024
cho0o0
1
420
成長期に歩みを止めないための創業期の開発文化形成
mayah
6
420
エンジニアの生存戦略 〜クラウド潮流の経験から紐解く技術トレンドのメカニズムと乗りこなし方〜
shimy
9
1.9k
20240717_イケコパ代表Copilot_in_Teams会社でこう使ってます
ponponmikankan
2
430
ここがすごいよ! AWS Systems Manager!
saichan11
0
1.8k
E2Eテスト自動化プラットフォームにおけるAIの活用
shift_evolve
0
190
テスト・設計研修【MIXI 24新卒技術研修】
mixi_engineers
PRO
0
170
Featured
See All Featured
Debugging Ruby Performance
tmm1
71
11k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
353
29k
Imperfection Machines: The Place of Print at Facebook
scottboms
262
13k
Rebuilding a faster, lazier Slack
samanthasiow
78
8.5k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
17
1.5k
Git: the NoSQL Database
bkeepers
PRO
423
64k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
245
1.2M
How STYLIGHT went responsive
nonsquared
93
5k
Building Adaptive Systems
keathley
34
2k
How to train your dragon (web standard)
notwaldorf
79
5.5k
What the flash - Photography Introduction
edds
65
11k
Fantastic passwords and where to find them - at NoRuKo
philnash
42
2.7k
Transcript
xaringan パッケージの内容をちょっとだけ fukuoka.R / Yakitori.R kazutan 2019-10-11
今⽇のお話 xaringanパッケージとは 実はエグい実装その1 実はエグい実装その2 2 / 17
xaringan パッケージとは R NinjaことYihui作のパッケージ 基本的な情報 R Markdownでスライドを作成できる remark.jsというライブラリを活⽤ 気付いたら世界各地で流⾏った このスライドもそうです
特徴 renderが軽量 chunkの評価は別 リアルタイムで編集をPreviewできる 他のRmdスライドテンプレートとはちょいちょい書き⽅が違う 例えばスライド区切りが だったり 3 / 17
xaringan 、内部的にはかなりエグい remark.jsを利⽤している remark.jsはmarkdown記法の⽂字列を読み込んでスライド化 実はこれが問題となる(後述) R Ninjaは「隠れ蓑の術」でクリアした リアルタイム編集(markdownレンダリング) 本来R MarkdownはrenderしないとViewerに出せない
R Ninjaはこれを「無限⽉読」(個⼈的には千⾥眼?)でクリアした 今⽇はこのあたりを簡単に紹介 4 / 17
おさらい: R Markdown の処理 詳しくは以下の記事を参照: R Markdownの内部とテンプレート開発 https://kazutan.github.io/TokyoR61/intoTheRmarkdown_d.html R Markdown
の流れ <Pandoc 系> <knit 系> .md pre_processor html, docs, pdf... output_format post_processor Pandoc .Rmd フォーマット テンプレ pre_knit .md output_format post_knit knit 5 / 17
忍法「隠れ蓑の術」 課題1 remark.jsはmarkdown記法を対象とするけど、Pandocを通すと強制的にhtmlにされてしま う。どうしたらいいか? R Ninjaの回答 スライドに表⽰させるドキュメント部分をバイパスさせればいい は? 6 /
17
忍法「隠れ蓑の術」 コード部分(1) バイパスさせるために、⼀時ファイルを準備 https://github.com/yihui/xaringan/blob/master/R/render.R#L84 コメントでも書いてますね tmp_md = tempfile('xaringan', fileext =
'.md') # store md content here (bypass Pandoc 7 / 17
忍法「隠れ蓑の術」 コード部分(2) 以下の処理をpre_processorとして準備 Rmdファイルからyamlとbodyを分離させる body部分をさっきの添付ファイルに書き込む https://github.com/yihui/xaringan/blob/master/R/render.R#L172-L185 pre_processor = function( metadata,
input_file, runtime, knit_meta, files_dir, output_dir ) { res = split_yaml_body(input_file) write_utf8(res$yaml, input_file) res$body = protect_math(res$body) content = htmlEscape(yolofy(res$body, yolo)) Encoding(content) = 'UTF-8' write_utf8(content, tmp_md) c( if (seal) c(' variable', 'title slide=true'), if (!identical(body, res$body)) c(' variable', 'math=true') ) }, 8 / 17
忍法「隠れ蓑の術」 コード部分(3) pandocによる変換処理の後に、Pandocの挿⼊機能を使って差し込む https://github.com/yihui/xaringan/blob/master/R/render.R#L119-L138 html_document2 = function( , includes =
list(), mathjax = 'default', pandoc_args = NULL ) { if (length(includes) 0) includes = list() includes$before_body = c(includes$before_body, tmp_md) includes$after_body = c(tmp_js, includes$after_body) 実際には細かい調整とかしてるけど、⼤まかにはこんな感じです 9 / 17
忍法「無限⽉読」 課題2 どうやってリアルタイムレンダリングしてるの? R Ninjaの回答 こんな感じで: 1. 簡易的なHTTPサーバーを起動させる servr パッケージで実現
2. 必要なライブラリを送る remark.jsなど 3. RmdファイルをHTTPサーバーへ送り、Viewerに表⽰させる Viewerについてはこちら tubeplayRパッケージはなぜRStudio上でYouTubeを再⽣できるのか 4. Rmdファイルをモニタリングし、変更を察知したらそれをサーバーへ送る rstudioapiを駆使している remark.jsがmdを読み込むというのがポイント 5. 変更を察知したら、Viewerを再読み込みさせる 10 / 17
まとめ R Ninjaまじすごい 11 / 17
おまけ 12 / 17
13 / 17
14 / 17
15 / 17
みんなNinja になろう 16 / 17
Enjoy! 17 / 17