Skip to content

Instantly share code, notes, and snippets.

@AlbertRapp
AlbertRapp / connected_ggiraph.R
Created January 25, 2023 19:39
connected_ggiraph.R
library(dplyr)
library(ggplot2)
library(patchwork)
library(ggiraph)
dat <- gapminder::gapminder |>
janitor::clean_names() |>
mutate(
# ID that is shared for boxplots (this one uses factors, i.e. numbers, as ID instead of continents)
@AlbertRapp
AlbertRapp / value_boxes_bslib.R
Created January 21, 2023 10:41
value_boxes_bslib.R
library(shiny)
library(bslib)
library(bsicons)
ui <- fluidPage(
theme = bslib::bs_theme(),
h1('One Box'),
fluidRow(
column(
@AlbertRapp
AlbertRapp / value_boxes_bs4dash.R
Created January 21, 2023 10:11
value_boxes_bs4dash.R
library(shiny)
library(bs4Dash)
ui <- dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(
h1('One Box'),
fluidRow(
actionButton('btn', 'Think of this button as some cool interactive element that reveals important information', width = '400px'),
@AlbertRapp
AlbertRapp / conneced_scatterplot.qmd
Created January 20, 2023 19:03
conneced_scatterplot.qmd
```{r}
setwd(here::here('connected_scatterplots'))
library(tidyverse)
library(lubridate)
library(patchwork)
library(showtext)
@AlbertRapp
AlbertRapp / values_boxes_bs4dash_app.R
Created January 17, 2023 16:54
values_boxes_bs4dash_app.R
library(shiny)
library(bs4Dash)
ui <- dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(skin = 'light'),
body = dashboardBody(
fluidRow(
actionButton('btn', 'Click me', width = '200px'),
bs4ValueBoxOutput('click_box', width = 4)
@AlbertRapp
AlbertRapp / values_boxes_bslib_app.R
Created January 17, 2023 16:41
values_boxes_bslib_app.R
library(shiny)
library(bslib)
library(bsicons)
ui <- fluidPage(
theme = bs_theme(),
title = 'Testapp',
h3('Test App'),
sidebarLayout(
@AlbertRapp
AlbertRapp / lollipop.R
Created December 31, 2022 19:22
Lollipop chart comparison with bar chart
library(tidyverse)
manufacturers <- mpg |>
count(manufacturer, sort = TRUE) |>
mutate(
manufacturer = str_to_title(manufacturer),
manufacturer = fct_reorder(manufacturer, n)
)
@AlbertRapp
AlbertRapp / 2022_day09.R
Created December 9, 2022 09:34
Advent of code 2022 Day 09
library(tidyverse)
# Helper function to do one single step
move_one_step <- function(head_tail_list, dir) {
n <- length(head_tail_list)
for (i in seq_along(head_tail_list)[-n]) {
# Get coordinates of current head-tail-pair
head_x <- head_tail_list[[i]]$x[length(head_tail_list[[i]]$x)]
head_y <- head_tail_list[[i]]$y[length(head_tail_list[[i]]$y)]
tail_x <- head_tail_list[[i + 1]]$x[length(head_tail_list[[i + 1]]$x)]
@AlbertRapp
AlbertRapp / blog_fcts.R
Created December 5, 2022 21:12
Blog post functions wrapped
# Most of the code has been adapted from
# https://nrennie.rbind.io/blog/2022-12-03-how-to-make-your-own-rstats-wrapped/
setwd(here::here('blog_fcts/'))
base_path <- 'Your_own_file_path_to_Blog_directory'
files <- list.files(
path = base_path,
recursive = TRUE
)
@AlbertRapp
AlbertRapp / 2022_Day01.R
Created December 1, 2022 08:19
Advent of Code 2022 - Day 1
library(tidyverse)
calories_input <- read_lines('data/2022_day01.txt')
total_calories_per_elf <- tibble(
calories = parse_number(calories_input)
) |>
mutate(elf = cumsum(if_else(is.na(calories), 1, 0))) |>
group_by(elf) |>
summarise(calories = sum(calories, na.rm = T))