Skip to content

Instantly share code, notes, and snippets.

View gshotwell's full-sized avatar

Gordon Shotwell gshotwell

  • Halifax, Nova Scotia
View GitHub Profile
@gshotwell
gshotwell / gist:eed0bda3ac0e7fa7a7a862cff094cf0d
Created July 6, 2023 13:14
Shiny todo with insert/remove modules
from shiny import App, render, ui, reactive, module
from htmltools import TagList
app_ui = ui.page_fluid(
ui.row(
# add space from the left
ui.column(3),
# center with content
ui.column(
6,
import datetime
from typing import Dict, List, Optional, Tuple
import astropy.units as u
import matplotlib.dates as mpldates
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pytz
import suntime
@gshotwell
gshotwell / gist:b19ef520b6d56f61a830fabb3454965b
Created September 26, 2022 16:01
Time series with breaks
library(tidyverse)
library(lubridate)
df <- tibble(
dist1 = sort(rnorm(100, 5, 2)),
dist2 = sort(rnorm(100, 8, 3)),
dist4 = sort(rnorm(100, 15, 1)),
date = seq.Date(from = ymd("2022-01-01"), ymd("2022-04-10"), by = "day")
)
library(tidyverse)
survey <- tibble::tribble(
~id, ~q_1, ~q_2, ~q_3,
1L, "good", "bad", "neutral",
2L, "neutral", "good", "neutral",
3L, "bad", "neutral", "neutral",
4L, "neutral", "good", "neutral",
5L, "bad", "good", "neutral",
6L, "bad", "bad", "neutral"
library(tidyverse)
library(janitor)
library(RcppRoll)
deaths <- read_csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv")
deaths <- deaths %>%
rename(province_state = `Province/State`,
country_region = `Country/Region`) %>%
pivot_longer(-c("province_state", "country_region", "Lat", "Long"),
library(tidyverse)
library(RcppRoll)
library(lubridate)
library(broom)
covid <- read_csv("https://covid.ourworldindata.org/data/owid-covid-data.csv") %>%
filter(location != "World")
covid <- covid %>%
group_by(iso_code) %>%
library(tidyverse)
library(rgeos)
library(RcppRoll)
library(rworldmap)
data <- read_csv("https://covid.ourworldindata.org/data/owid-covid-data.csv") %>%
filter(location != "World")
plot_df <- data %>%
group_by(iso_code) %>%
select_random <- function(tbl, n_records) {
tbl <- tbl %>%
dplyr::mutate(rand = random()) %>%
dplyr::compute() %>%
dplyr::arrange(.data$rand) %>%
dplyr::filter(dplyr::row_number(.data$rand) <= !!n_transactions) %>%
dplyr::select(-.data$rand)
}
tbl %>%
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
call <- substitute(ifelse(v == 1,
"banana",
ifelse(v == 2,
2,
NA))
)
parse_ifelse <- function(call) {
if (deparse(call[[3]][[1]]) == "ifelse") {
top_call <- deparse(call[[2]])