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
0
440
RでHex ~ R + Shinylive + Quarto = 最強 ~
Japan.R 2024のLTで利用したスライドです。
Enjoy!
statditto
December 07, 2024
Tweet
Share
More Decks by statditto
See All by statditto
NDCG is NOT All I Need
statditto
2
730
t検定は中心局限定理の夢を見るか?
statditto
2
640
相関データとサンプルサイズ設計 ~デルタ法のサンプルサイズ設計には気をつけて~
statditto
1
700
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
Rebuilding a faster, lazier Slack
samanthasiow
84
9.2k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
116
20k
BBQ
matthewcrist
89
9.9k
Making the Leap to Tech Lead
cromwellryan
135
9.6k
How STYLIGHT went responsive
nonsquared
100
5.9k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
For a Future-Friendly Web
brad_frost
180
10k
Practical Orchestrator
shlominoach
190
11k
Bash Introduction
62gerente
615
210k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.5k
Become a Pro
speakerdeck
PRO
29
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