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
690
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
3.2k
t検定は中心局限定理の夢を見るか?
statditto
3
1.1k
相関データとサンプルサイズ設計 ~デルタ法のサンプルサイズ設計には気をつけて~
statditto
1
920
Featured
See All Featured
Odyssey Design
rkendrick25
PRO
2
730
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
240
Navigating Team Friction
lara
192
16k
Done Done
chrislema
186
16k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
650
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
The Curse of the Amulet
leimatthew05
2
13k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
600
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
The Spectacular Lies of Maps
axbom
PRO
1
850
KATA
mclloyd
PRO
35
15k
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