Skip to content

Instantly share code, notes, and snippets.

@trestletech
trestletech / server.R
Last active February 2, 2022 09:47
A Shiny app combining the use of dplyr and SQLite. The goal is to demonstrate a full-fledged, database-backed user authorization framework in Shiny.
library(shiny)
library(dplyr)
library(lubridate)
# Load libraries and functions needed to create SQLite databases.
library(RSQLite)
library(RSQLite.extfuns)
saveSQLite <- function(data, name){
path <- dplyr:::db_location(filename=paste0(name, ".sqlite"))
@gluc
gluc / app.R
Last active November 23, 2022 10:14
Shiny CRUD
library(shiny)
library(shinyjs)
# Get table metadata. For now, just the fields
# Further development: also define field types
# and create inputs generically
GetTableMetadata <- function() {
fields <- c(id = "Id",
@benmarwick
benmarwick / 000_geom_bag.r
Last active March 28, 2024 10:52
Basic bagplot geom for ggplot2
#' Bagplot
#'
#' The bag geom is useful for graphical summaries of scatterplots. It
#' is effective at showing the location, spread, skewness, and
#' outliers of a data set.
#'
#' A bagplot is a bivariate generalization of the well known boxplot. It
#' was proposed by Rousseeuw, Ruts, and Tukey. This geom plots bagplots that
#' are very similar to the one described in Rousseeuw et al. and
#' uses code from their bagplot functions in the aplpack pacakge.
@klmr
klmr / generator.md
Last active August 28, 2022 02:26
Python-like generators in R

A little experiment using restarts.

(And while we’re at it, let’s torture R’s syntax a little.)

![screenshot][]

In the following we will be using R’s “restarts” feature to implement the state machine that drives generators in languages such as Python. Generators allow lazily generating values on demand: a consumer invokes a generator, and consumes values as they are produced. A new value is only produced once the previous one has been consumed.

@timelyportfolio
timelyportfolio / .block
Last active August 18, 2019 17:07 — forked from ramnathv/concaveman.R
Using Concaveman in R using V8 with beeswarm (fork)
license: mit
height: 100
library(purrr)
library(dplyr)
row_count <- function(.x, .f){
.f <- as_mapper(.f)
reduce(.x, function(x, y) x + .f(y), .init = 0 )
}
data <- tribble(
~x, ~y, ~z,
@john-guerra
john-guerra / .block
Last active July 17, 2022 17:15
GeoJson Map of Bogotá
license: mit
@Kcnarf
Kcnarf / .block
Last active August 17, 2018 14:16
d3-voronoi-map usage
license: mit
@dpseidel
dpseidel / default_aes.md
Last active February 12, 2021 17:08
Default ggplot2 aesthetics table

Default ggplot2 aesthetics by geom.

geom alpha angle colour family fill fontface height hjust lineheight linetype shape size stroke vjust weight width xmax xmin ymax ymin
GeomAbline NA black 1 0.5
GeomAnnotationMap NA NA grey20 1 0.5
GeomArea NA NA grey20 1 0.5
GeomBar NA NA grey35 1 0.
library(gganimate) # thomasp85/gganimate
library(cartogram)
library(geogrid) # Need github version jbaileyh/geogrid
library(rnaturalearth)
library(sf)
library(scico)
us <- ne_states('united states of america', returnclass = 'sf')
us <- us[!us$woe_name %in% c('Alaska', 'Hawaii'), ]
us <- st_transform(us, '+proj=eqdc +lat_0=39 +lon_0=-96 +lat_1=33 +lat_2=45 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs')