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
430
RでHex ~ R + Shinylive + Quarto = 最強 ~
Japan.R 2024のLTで利用したスライドです。
Enjoy!
statditto
December 07, 2024
Tweet
Share
More Decks by statditto
See All by statditto
t検定は中心局限定理の夢を見るか?
statditto
2
560
相関データとサンプルサイズ設計 ~デルタ法のサンプルサイズ設計には気をつけて~
statditto
1
690
Featured
See All Featured
The Invisible Side of Design
smashingmag
301
51k
Speed Design
sergeychernyshev
32
1.1k
Designing Experiences People Love
moore
142
24k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
How to train your dragon (web standard)
notwaldorf
96
6.3k
Embracing the Ebb and Flow
colly
88
4.8k
KATA
mclloyd
32
15k
The World Runs on Bad Software
bkeepers
PRO
71
11k
A better future with KSS
kneath
239
17k
Site-Speed That Sticks
csswizardry
11
890
The Art of Programming - Codeland 2020
erikaheidi
56
14k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
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