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
RでHex ~ R + Shinylive + Quarto = 最強 ~
Search
statditto
December 07, 2024
640
0
Share
RでHex ~ R + Shinylive + Quarto = 最強 ~
Japan.R 2024のLTで利用したスライドです。
Enjoy!
statditto
December 07, 2024
More Decks by statditto
See All by statditto
NDCG is NOT All I Need
statditto
2
3k
t検定は中心局限定理の夢を見るか?
statditto
2
770
相関データとサンプルサイズ設計 ~デルタ法のサンプルサイズ設計には気をつけて~
statditto
1
860
Featured
See All Featured
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
140
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
120
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.5k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
230
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
680
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
490
Unsuck your backbone
ammeep
672
58k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
380
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.6k
Transcript
RでHex R + Shinylive + Quarto = 最強 2024/12/07 statditto
@Japan.R 2024
自己紹介 • X : @st4tditt0 • B:@statditto • R: ◦
好きなパッケージ紹介ドラゴン @Tokyo.R 112 ◦ 相関データのサンプルサイズ設計 @Tokyo.R 115
Rといえば何角形 ?
Rといえば六角形! (Hex)
六角形といえば?
Hex (Board Game)
Hex (Board Game) • 二人が交互にコマを置く • 対辺を繋げたら勝ち • Each player
placed stones. • They can win connecting their sides.
Write with R!
How to make Make Board Place stone Check win End
• 必要な機能 ◦ 盤面生成 ◦ 石の配置 ◦ 勝利条件チェック • interactiveにやるなら サーバーが必須......?
Shinylive • サーバー無しでShinyを利用できる![1] ◦ WebR君がいい感じにしてくれている • 最近のアップデートでより便利に[2, 3] • Shiny
apps without Shiny server. ◦ Recently updated make Shinylive more usefull. Yutaniさんに感謝 🙏
盤面生成 Make board ggplot2::stat_summary_hex() やgeom_hex()で六角形の描写 は可能 密度プロットが簡単に書ける
盤面生成 ggplot(long_board, aes(x = col, y = row, z =
player)) + stat_summary_hex( binwidth = c(1, 1), linewidth = 1, colour = "black", fun = function(x) mean(x, na.rm = TRUE) ) + scale_fill_gradient2( low = "white", mid = "#FF0033", high = "#00B900", midpoint = 1, na.value = "grey" ) + coord_fixed() Make board データの持ち方を工夫して ゴリ押し それっぽい
石の配置 ui <- fluidPage( titlePanel("Hex Game"), mainPanel( plotOutput("hex_board", click =
"plot_click") ) ... ) server <- function(input, output) { input$plot_click # ここに色々入ってる感じ ... } Place stone Shinyはグラフのclick位置の 座標を簡単に取れる Atusyさん に 感 謝🙏 [4]
勝利条件 dfs <- function(board, player, visited, row, col) { size
<- nrow(board) if (visited[row, col] || board[row, col] != player) { return(FALSE) } visited[row, col] <- TRUE neighbors <- get_neighbors(row, col, size) for (neighbor in neighbors) { if (dfs(board, player, visited, neighbor[1], neighbor[2])) { return(TRUE) } } return(FALSE) } Check winner DFS(深さ優先探索)で ゴリ押し 面白味なし!
完成! • とりあえず動く[5] ◦ Quarto拡張機能[6]が便利 • リファクタリングして R言語 Advent Calendar
2024で 改めて紹介します!
Why R?
Because it's fun!
Enjoy!
ref 1. Shinylive 2. WebAssembly roundup part 2: Shinylive 0.8.0
3. shinylive v0.8.0 のリリースノートを眺めてみる(2024/11/26) 4. Shiny でプロットを click したり brush したりした時に得られるデータま とめ 5. https://github.com/statditto/hex_with_shinylive 6. https://github.com/quarto-ext/shinylive