Skip to content

Instantly share code, notes, and snippets.

View srvanderplas's full-sized avatar

Susan VanderPlas srvanderplas

View GitHub Profile
@srvanderplas
srvanderplas / Scrape_Weather.R
Created January 15, 2019 03:29
Weather from TimeAndDate.com
library(RSelenium)
library(rvest)
library(tidyverse)
# Newer versions of Selenium don't work that well...
rs_driver <- rsDriver(port = 4567L, version = "3.12.0")
rd <- rs_driver$client
rd$setImplicitWaitTimeout(milliseconds = 5000)
url <- function(m, y) sprintf("https://www.timeanddate.com/weather/@4846834/historic?month=%d&year=%d", m, y)
@srvanderplas
srvanderplas / app.R
Created December 13, 2018 16:13
Tiny Shiny App for debugging ODBC connections
shinyApp(ui = fluidPage(textOutput("con"), textOutput("fileexists")),
server = function(input, output) {
output$con <- renderPrint(con)
output$fileexists <- renderPrint(list.files(here::here()))
})
@srvanderplas
srvanderplas / app.R
Created December 13, 2018 16:04
Tiny Shiny App for checking path issues
shinyApp(ui = fluidPage(textOutput("pwd")),
server = function(input, output) {
output$pwd <- renderText(list.files(here::here()))
})
@srvanderplas
srvanderplas / table-grob.R
Created November 27, 2018 18:08
Attempt at grob-based table
main.table <- data.frame(Results = c("Exclusion", "Identification"), `Same Source` = c("Missed Identification", "Correct Identification"), `Different Source` = c("Correct Exclusion", "Wrong Identification"))
names(main.table) <- c("", "Same Source", "Different Source")
blank <- textGrob("")
gt <- textGrob("Ground Truth", gp = gpar(fontsize = 14, fontface = "bold"))
res <- textGrob("Results", rot = 90, gp = gpar(fontsize = 14, fontface = "bold"))
mt <- tableGrob(main.table, rows = NULL, theme = ttheme_default())
layout.matrix <- matrix(c(1, 1, 2, 2, 3, 4, 4, 4, 5, 4, 4, 4, 5, 4, 4, 4), nrow = 4, byrow = T)
@srvanderplas
srvanderplas / emoji.Rmd
Created August 28, 2018 13:48
Emoji test in Rmarkdown
---
title: "Emoji"
author: "Susan VanderPlas"
date: "8/28/2018"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
@srvanderplas
srvanderplas / 100 days of weather.R
Last active June 14, 2016 14:18
Demonstrating that 100 days of weather can be used to predict reasonable weather in 3 days
# --- Packages -----------------------------------------------------------------
library(ggplot2) # Plots
library(magrittr) # Pipes
library(dplyr) # Split-Apply-Combine
library(tidyr) # Reshape data
library(stringr) # String manipulation
library(lubridate) # Dates and times
library(readr) # Read in csv/tsv/fwf data
library(readxl) # Read in excel data
# ------------------------------------------------------------------------------
@srvanderplas
srvanderplas / Plot fragment hook
Created March 24, 2015 17:59
Knitr plot fragment hook for reveal.js
c0 <- knitr::knit_hooks$get('chunk')
knitr::knit_hooks$set(
list(
chunk=function(x,options){
if(is.null(options$class) & is.null(options$fragIndex)){
c0(x, options)
} else if(is.null(options$fragIndex)) {
classidx <- which(names(options)=="class")
@srvanderplas
srvanderplas / animint-line-tooltip.R
Last active August 29, 2015 14:17
Reproducible example that tooltips do not currently work on lines in Animint.
library(animint)
library(ggplot2)
data <- data.frame(x=rep(1:10, times=2), y=c(1:10, 2*(1:10)), type=rep(c("line1","line2"), each=10))
plot1 <-
ggplot() +
geom_line(aes(x=x, y=y, group=type, color=type, tooltip=type), data=data)
# animint2dir(list(lineplot=plot1), out.dir="~/Web/animintexample3", open.browser=T)
@srvanderplas
srvanderplas / Unicode.Rmd
Last active August 29, 2015 14:12
Unicode in ggplot2/shiny/markdown
---
title: "UnicodeTest"
author: "Susan VanderPlas"
date: "01/06/2015"
output: html_document
---
Testing whether it's a browser/rendering issue, which makes no sense to me, but it wouldn't be the strangest error I've come across:
```{r}
@srvanderplas
srvanderplas / server.R
Created January 6, 2015 00:35
Working Example of Unicode Issue with ggplot2 and shiny
library(shiny)
library(ggplot2)
# library(Cairo)
# options(shiny.usecairo=T)
# Define colors and shapes
colors <- c("#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd",
"#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf")
shapes1 <- c(1,0,3,4,8,5,2,6,-0x25C1, -0x25B7)
shapes2 <- 1:10