Skip to content

Instantly share code, notes, and snippets.

## Start with the code and data here: https://github.com/fivethirtyeight/data/blob/master/police-deaths/plot.R
## Then:
## Calculate total deaths by year
dat <- data_for_plot %>%
group_by(year) %>%
mutate(total = sum(count))
## Colors I chose
mycolors <- c("#00bf7b", "#59004d", "#ffcb89", "#a76e61", "#ac270d", "#7890ff",
@jcheng5
jcheng5 / app.R
Last active February 3, 2024 17:34
Using OAuth2 with Shiny
library(shiny)
# WARNING: This sketch does not make proper use of the "state" parameter.
# Doing so usually involves using cookies, which can be done with the
# Rook package but I have not done that here. If you choose to use this
# approach in production, please check the state parameter properly!
APP_URL <- if (interactive()) {
# This might be useful for local development. If not, just hardcode APP_URL
# to the deployed URL that you'll provide a few lines below.
@calligross
calligross / app.R
Last active August 23, 2023 17:22
Shiny Cookie Based Authentication Example, please visit https://calligross.de/post/using-cookie-based-authentication-with-shiny/ for more information.
library(shiny)
library(shinyjs)
if (!dir.exists('www/')) {
dir.create('www')
}
download.file(
url = 'https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js',
destfile = 'www/js.cookie.js'
@volpefoxx
volpefoxx / add_urls_to_playlist.py
Last active February 17, 2022 08:56 — forked from anonymous/add_urls_to_playlist.py
Make YouTube playlist from posts in Facebook group.
import requests
import json
import re
from more_itertools import unique_everseen
with open("urls.json", "r", encoding="utf-8") as fp:
urls = json.load(fp)
# lots of regex to extract video ID from different types of YouTube links
def get_id(url):
@jcheng5
jcheng5 / filters.R
Last active September 12, 2024 22:48
library(shiny)
columnFilterUI <- function(id) {
ns <- NS(id)
uiOutput(ns("filter_container"))
}
columnFilter <- function(input, output, session, df, col_num, choice_filter) {
# This renders a selectInput and only re-renders when the selected data
# frame changes. (i.e. it doesn't re-render when filters change state.)
@MarkEdmondson1234
MarkEdmondson1234 / dynamicSelectShinyModule.R
Last active November 21, 2020 00:09
Shiny modules for creating dynamic SelectInputs
library(shiny)
#' Safe subset
#'
#' @param df Dataframe
#' @param column One name of column to subset within
#' @param subset Vector of entries in column to subset to
#'
#' If column not in df, returns back the df
safeSubset <- function(df, column, subset){
@wch
wch / app.r
Last active February 2, 2025 16:41
Shiny example app with dynamic number of plots
max_plots <- 5
ui <- fluidPage(
headerPanel("Dynamic number of plots"),
sidebarPanel(
sliderInput("n", "Number of plots", value=1, min=1, max=5)
),