Skip to content

Instantly share code, notes, and snippets.

View gadenbuie's full-sized avatar

Garrick Aden-Buie gadenbuie

View GitHub Profile
@gadenbuie
gadenbuie / app.R
Created March 6, 2025 21:30
shiny cows
library(shiny)
library(bslib)
library(dplyr)
library(ggplot2)
# Sample cow data
cow_data <- data.frame(
name = c("Bessie", "Daisy", "Buttercup", "Molly", "Clover", "Rosie", "Bella", "Penny", "Lulu", "Mabel"),
breed = c("Holstein", "Jersey", "Angus", "Hereford", "Guernsey", "Simmental", "Holstein", "Jersey", "Angus", "Guernsey"),
milk_per_day = c(28, 25, 0, 0, 27, 0, 30, 24, 0, 26),

App Install Plan

Critical

@gadenbuie
gadenbuie / 01-hello-dashboards.R
Last active December 4, 2024 13:08
Example apps using bslib v0.5.0
# https://shiny.posit.co/blog/posts/bslib-dashboards/#hello-dashboards
library(shiny)
library(bslib)
library(ggplot2)
# Setup -------------------------------------------------------------------
data(penguins, package = "palmerpenguins")
---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
lib_dir: libs
css:
- default
snps <-
list(r = "~/.config/rstudio/snippets/r.snippets") %>%
purrr::map(readLines, warn = FALSE) %>%
purrr::map(paste, collapse = "\n") %>%
purrr::map(trimws) %>%
purrr::map(strsplit, split = "(^|\n)snippet ") %>%
purrr::map_depth(2, ~ .x[.x != ""]) %>%
purrr::map_depth(2, ~ {
nm <- gsub("^([^\n\t ]+).*", "\\1", .x)
names(.x) <- nm
---
title: Reading a YAML chunk
output: github_document
---
Here's a simple YAML chunk (with the label `config`):
```{yaml config}
default:
user: "garrick"
@gadenbuie
gadenbuie / git-remotes-https.R
Created August 20, 2024 12:36
git, convert remotes from ssh to https
library(dplyr)
remotes <- gert::git_remote_list()
remotes |>
mutate(
url = sub("git@github.com:", "https://github.com/", url, fixed = TRUE),
url = sub(".git", "", url, fixed = TRUE)
) |>
purrr::pwalk(function(name, url) {
alias_input_from_shiny <- function(
input = "actionLink",
update = NULL,
new_input = NULL,
new_update = NULL
) {
if (is.null(update)) {
update <- paste0("update", toupper(substr(input, 1, 1)), substring(input, 2))
}
@gadenbuie
gadenbuie / render_toc.R
Last active May 16, 2024 20:09
Generate Manual Table of Contents in (R)Markdown Documents
#' Render Table of Contents
#'
#' A simple function to extract headers from an RMarkdown or Markdown document
#' and build a table of contents. Returns a markdown list with links to the
#' headers using
#' [pandoc header identifiers](http://pandoc.org/MANUAL.html#header-identifiers).
#'
#' WARNING: This function only works with hash-tag headers.
#'
#' Because this function returns only the markdown list, the header for the
@gadenbuie
gadenbuie / app.R
Last active May 3, 2024 13:52
Big Shiny Easy Button
library(shiny)
if (!requireNamespace("praise", quietly = TRUE)) {
install.packages("praise")
}
ui <- shiny::fillPage(
bootstrap = FALSE,
actionLink("easy", class = "easy-button", "easy"),
uiOutput("not-hard"),