Skip to content

Instantly share code, notes, and snippets.

@nstrayer
nstrayer / app.py
Created June 27, 2023 20:36
ShinyComponent app demonstrating flexible cards
from htmltools import Tag
from shiny import App, render, ui
import shinycomponent as sc
# Basic paragraph tag with some lorem ipsum text inside of it
lorem_ipsum = ui.p("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
app_ui = sc.page_dashboard(
sc.grid(
@nstrayer
nstrayer / fun_w_rapply.R
Last active March 12, 2021 21:44
Experiments with the function rapply in R's base library
library(magrittr)
str_replace_all <- function(text, pattern, replacement){
gsub(pattern = pattern, replacement = replacement, x = text, perl = TRUE)
}
str_remove_all <- function(text, pattern){
str_replace_all(text, pattern = pattern, replacement = "")
}
@nstrayer
nstrayer / self_rendering_md.css
Created February 4, 2020 20:34
CSS to make HTML build from basic markdown look like generating markdown but with the style preserved
@import url('https://fonts.googleapis.com/css?family=Inconsolata&display=swap');
body {
--text-color: #2b2a2a;
--link-color: #005fb1;
font-family: 'Inconsolata', monospace;
font-size: 15px;
color: var(--text-color);
}
@nstrayer
nstrayer / simulate_mnar_data.R
Created January 21, 2020 21:38
R Script to simulate missing not at random data and look at performance of different imputation strategies.
library(tidyverse)
n <- 150
sensitivity_threshold <- 5
data <- tibble(
a = rgamma(n = n, shape = 5, rate = 0.5),
b = rgamma(n = n, shape = a/2, rate = 0.5)
)
generate_missing_data <- function(i){
@nstrayer
nstrayer / no_good_very_bad_data.csv
Created August 8, 2018 21:47
simple csv of some hard-to-histogram data.
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
x
0.8749728356504094
0.9658539380522311
1.0988786266989092
0.9270070375557564
1.1795131996034487
1.0716089699247264
0.8728550463211999
1.0682964292826937
0.9766832723965019
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script>(function() {
// If window.HTMLWidgets is already defined, then use it; otherwise create a
// new object. This allows preceding code to set options that affect the
// initialization process (though none currently exist).
window.HTMLWidgets = window.HTMLWidgets || {};
We can't make this file beautiful and searchable because it's too large.
time,direction,accel,label,recording_id,caster
0.057,m_x,-0.1,Alohomora,1_aiknf,Nick
0.102,m_x,-0.15,Alohomora,1_aiknf,Nick
0.154,m_x,-0.36,Alohomora,1_aiknf,Nick
0.205,m_x,-0.52,Alohomora,1_aiknf,Nick
0.254,m_x,-0.92,Alohomora,1_aiknf,Nick
0.307,m_x,-1.32,Alohomora,1_aiknf,Nick
0.356,m_x,-1.23,Alohomora,1_aiknf,Nick
0.407,m_x,-1.02,Alohomora,1_aiknf,Nick
0.458,m_x,-0.99,Alohomora,1_aiknf,Nick
library(tidyverse)
library(htmltools)
# devtools::install_github('ramnathv/htmlwidgets')
library(htmlwidgets)
# devtools::install_github('timelyportfolio/d3r')
library(d3r)
data <- data_frame(x = rnorm(50), y = rnorm(50));
browsable(
{"edges":[{"from":1,"to":5550},{"from":1,"to":5551},{"from":2,"to":5559},{"from":2,"to":5560},{"from":2,"to":5561},{"from":3,"to":5550},{"from":3,"to":5551},{"from":3,"to":5559},{"from":3,"to":5560},{"from":4,"to":5550},{"from":4,"to":5551},{"from":4,"to":5552},{"from":4,"to":5553},{"from":4,"to":5555},{"from":4,"to":5556},{"from":4,"to":5561},{"from":5,"to":5550},{"from":5,"to":5551},{"from":6,"to":5550},{"from":6,"to":5551},{"from":7,"to":5550},{"from":7,"to":5551},{"from":8,"to":5558},{"from":9,"to":5550},{"from":9,"to":5551},{"from":9,"to":5561},{"from":10,"to":5550},{"from":10,"to":5551},{"from":10,"to":5552},{"from":10,"to":5554},{"from":10,"to":5555},{"from":10,"to":5556},{"from":10,"to":5559},{"from":11,"to":5550},{"from":11,"to":5551},{"from":11,"to":5561},{"from":12,"to":5550},{"from":12,"to":5551},{"from":13,"to":5550},{"from":13,"to":5551},{"from":14,"to":5550},{"from":14,"to":5551},{"from":14,"to":5561},{"from":15,"to":5550},{"from":15,"to":5551},{"from":16,"to":5557},{"from":16,"to":5561},{"from
library(tidyverse)
get_boot_int <- function(n){
data <- data_frame(
outcome = rnorm(n, 60, 20),
treat = sample(c(0,1), n, replace = T)
) %>%
mutate(outcome = ifelse(treat == 1, outcome + 5, outcome))
data %>%
group_by(treat) %>%