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
350
RでHex ~ R + Shinylive + Quarto = 最強 ~
Japan.R 2024のLTで利用したスライドです。
Enjoy!
statditto
December 07, 2024
Tweet
Share
More Decks by statditto
See All by statditto
相関データとサンプルサイズ設計 ~デルタ法のサンプルサイズ設計には気をつけて~
statditto
1
600
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
39
1.8k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.7k
Typedesign – Prime Four
hannesfritz
42
2.7k
Six Lessons from altMBA
skipperchong
28
3.8k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
The Invisible Side of Design
smashingmag
299
51k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
6
690
For a Future-Friendly Web
brad_frost
179
9.8k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
Statistics for Hackers
jakevdp
799
220k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
4
170
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