Skip to content

Instantly share code, notes, and snippets.

@AlbertRapp
AlbertRapp / data_viewer_app_modularized.R
Created August 29, 2022 15:05
This is a non-modularized Shiny app to explore different data sets.
setwd(here::here('shiny_modules'))
library(shiny)
library(ggplot2)
data_viewer_UI <- function(id, my_data_set) {
ns <- NS(id)
tagList(
sidebarLayout(
sidebarPanel(
@AlbertRapp
AlbertRapp / usa_religions.qmd
Created September 10, 2022 20:28
Two sample plots for pie charts with lots of slices
---
output: html_document
editor_options:
chunk_output_type: console
---
```{r}
setwd(here::here('religions_usa'))
library(tidyverse)
@AlbertRapp
AlbertRapp / shinyjs_toggle.R
Created September 22, 2022 18:38
shinyjs toggle
library(shiny)
library(ggplot2)
library(dplyr)
ui <- fluidPage(
shinyjs::useShinyjs(),
theme = bslib::bs_theme(
# Colors (background, foreground, primary)
bg = 'white',
fg = '#06436e',
@AlbertRapp
AlbertRapp / paired_bar_plot_alternative.qmd
Last active October 7, 2022 18:37
Code for dumbbell charts and slope charts. Not commented. Will be converted into a blog post.
---
output: html_document
editor_options:
chunk_output_type: console
---
```{r}
#| dpi: 300
#| fig-height: 5
@AlbertRapp
AlbertRapp / linear_gradient_rect.R
Created October 4, 2022 19:53
Hopefully helpful function for Tanya's ggplot phone
library(ggplot2)
library(grid)
library(ggpp)
rect_gr <- grid.rect(
gp = gpar(
col = NA,
fill = linearGradient(
colours = thematic::okabe_ito(2),
# Units is npc (so values between 0 and 1)
x1 = 1, y1 = 1,
@AlbertRapp
AlbertRapp / iphone_plot_tanya.qmd
Created October 5, 2022 18:36
Little adjustment to make Tanya's iphone have a linear gradient wallpaper.
---
output: html_document
editor_options:
chunk_output_type: console
---
This code is adjusted from Tanya Shapiro.
See https://github.com/tashapiro/TidyTuesday/blob/master/2022/W40/iphone-apps.R
Load packages
```{r}
library(tidyverse)
library(gt)
library(gtExtras)
library(svglite) # necessary for some gtExtras feature that {renv} seems to not detect otherwise
```
@AlbertRapp
AlbertRapp / images_icons_ggplots_gt.qmd
Created October 26, 2022 11:39
icons, images and ggplots
Add emojis and icons via the `emoji` package.
```{r}
library(tidyverse)
library(gt)
vegetables <- tibble(
Vegetable = c('eggplant', 'cucumber', 'broccoli', 'garlic', 'onion')
) |>
mutate(
Emoji = map_chr(Vegetable, emoji::emoji),
@AlbertRapp
AlbertRapp / penguins_table_gradient.R
Created October 26, 2022 14:30
penguins_table_gradient.R
library(tidyverse)
library(gt)
filtered_penguins <- palmerpenguins::penguins |>
filter(!is.na(sex))
penguin_weights <- palmerpenguins::penguins |>
filter(!is.na(sex)) |>
group_by(species) |>
summarise(
@AlbertRapp
AlbertRapp / fitness_tiers_table.qmd
Created October 28, 2022 09:37
fitness_tiers_table.qmd
Original table at https://codepen.io/supacode/pen/ExjbmgG
```{r}
library(tidyverse)
library(gt)
levels <- c('Standard', 'Popular', 'Golden', 'Ultimate')
prices <- c(15, 25, 35, 50)
names(prices) <- levels
features <- c('Beginner Classes', 'Training Overview', 'Personal Training', 'Olympic Weightlifting', 'Foundation Training')