Skip to content

Instantly share code, notes, and snippets.

View matt-dray's full-sized avatar
®️

Matt Dray matt-dray

®️
View GitHub Profile
@matt-dray
matt-dray / gachr.R
Created March 26, 2025 17:37
A simple R Shiny app to demonstrate use of reactive values via a gacha-style interface
ui <- bslib::page_fillable(
bslib::card(
bslib::card_header("Gacha"),
shiny::textOutput("rolled_details"),
shiny::textOutput("rolled_emoji"),
shiny::actionButton("btn_roll", "Roll!")
),
bslib::card(
bslib::card_header("Collection"),
shiny::tableOutput("dex")
@matt-dray
matt-dray / aftables-hex.R
Last active February 28, 2025 23:39
The hex sticker logo for {aftables} made with {gex} and {grid}
# hex sticker for {aftables}:
# https://github.com/best-practice-and-impact/aftables
# having installed the Free Sans font:
# https://www.fontspace.com/freesans-font-f13276
# and installed {gex}:
remotes::install_github("matt-dray/gex")
# and {ggplotify}:
install.packages("ggplotify")
@matt-dray
matt-dray / app.R
Last active August 8, 2024 08:49
Quick demo Shiny app with {bslib} navbar with tabs and panels, and a sidebar with (conditional) dropdown selectors and checkboxes
set.seed(123)
n <- 5
scheme <- paste("Scheme", 1:n)
mitigator <- paste("Mitigator", LETTERS[1:n])
combos <- tidyr::crossing(scheme, mitigator)
nrows <- nrow(combos)
dat <- combos |>
dplyr::mutate(
mitigator_group = dplyr::if_else(
stringr::str_detect(mitigator, " [ABC]$"),
@matt-dray
matt-dray / responsive-facet-height.R
Created June 28, 2024 14:07
{ggplot2} plot-height determined by facet row count: halve the height of the output if the second facet row is missing
# Calculate how many plots will be produced
count_plots <- function(df, var) {
length(unique(df[[var]]))
}
# Plot faceted chart, save with height dependent on plot count
write_responsive_facets <- function(
df,
var = "species",
plot_count = count_plots(df, var),
@matt-dray
matt-dray / nara-grid.R
Last active June 25, 2024 08:04
Messing about with kenney.nl sprites on a grid with {nara}
# {nara} by Mike Cheng: https://coolbutuseless.github.io/package/nara/index.html
# Kenney by Kenney: https://www.kenney.nl
# Read png tiles
tile_paths <- list.files(
"~/Desktop/kenney/kenney_tiny-dungeon/Tiles",
pattern = ".png$",
full.names = TRUE,
recursive = TRUE
@matt-dray
matt-dray / compare-sheet-names.R
Last active June 21, 2024 15:43
Extract spreadsheet sheet-names from multiple workbooks into a list of vectors and compare between all pairs
# 1. Generate temporary Excel files ----
# Make a temporary spreadsheet with named sheets
make_temp_xlsx <- function(sheet_names) {
wb <- openxlsx2::wb_workbook()
for (sheet in sheet_names) wb <- wb |> openxlsx2::wb_add_worksheet(sheet)
temp <- openxlsx::temp_xlsx()
openxlsx2::wb_save(wb, temp)
}
@matt-dray
matt-dray / storage_read_json.R
Created June 20, 2024 13:16
Sketch for function in the style of `AzureStor::storage_read_*()` but for json/json.gz
#' Convenience Function: Read a (Zipped) JSON File from an Azure Container
#'
#' @param container A blob_container/storage_container object. Probably
#' generated by [connect_to_container].
#' @param file Character. Path to file within the container named by
#' `container`.
#'
#' @return A list.
#' @export
#'
@matt-dray
matt-dray / generate_num_format.R
Created May 28, 2024 19:54
Quick function to split a number and convert it to an Excel-style numFmt
generate_num_format <- function(number = 8634567.890) {
num_val <- number %/% 1
num_dp <- number %% 1
num_split <- strsplit(as.character(number), "\\.")[[1]]
n_dp <- nchar(num_split[2])
num_commas <- scales::number(as.numeric(num_val), big.mark = ",")
fmt_out <- gsub("[[:digit:]]", "#", num_commas)
@matt-dray
matt-dray / github-tag-and-release.md
Created May 24, 2024 14:21
Quick step-by-step to tag and release via GitHub
  1. On the repo homepage, click the text 'Releases' in the right-hand section.
  2. Click the 'Draft a new release' button (upper-right).
  3. Click the 'Choose a tag' button (upper-left). This is going to 'tag' this point in the Git history with the version number.
  4. Type in the box the version you're releasing, e.g. 'v0.1.1'.
  5. Click '➕ Create new tag: v0.1.1 on publish' that appears under the box.
  6. Click 'Generate release notes', which will autoname the release with the tag autofill the notes with a bullet per PR since the last release
  7. Click 'Publish release' button (lower-right) to publish the release and add the tag to the version history.
  8. Return to the repo's homepage, where you'll see that the version number has incremented under the 'Releases' section.
@matt-dray
matt-dray / github-etiquette.md
Last active May 17, 2024 12:02
Notes for a 'GitHub Etiquette' talk

Title

  • GitHub etiquette
  • GitHub in a small team
  • GitHub: what works for us
  • A loose GitHub playbook
  • GitHub is a team sport

Angle