Skip to content

Instantly share code, notes, and snippets.

@corynissen
corynissen / server.R
Created August 27, 2014 15:35
ggvis hack...
library(shiny)
library(ggvis)
shinyServer(function(input, output, session) {
df <- mtcars
df$id <- 1:nrow(df)
plot_data <- reactive({
df$x <- df[,input$x_var]
@corynissen
corynissen / server.R
Created August 25, 2014 18:32
ggvis shiny issue
library(shiny)
library(ggvis)
shinyServer(function(input, output, session) {
df <- mtcars
plot_data <- reactive({
df$x <- df[,input$x_var]
@corynissen
corynissen / server.R
Created July 14, 2014 14:57
ggmap click locator
library(shiny)
library(ggmap)
shinyServer(function(input, output) {
output$chicagoPlot <- renderPlot({
p <- qmap("chicago IL")
print(p)
})
@corynissen
corynissen / server.R
Created July 8, 2014 19:55
ggvis brushing to zoom
library(ggvis)
shinyServer(function(input, output, session) {
mtcars <- cbind(mtcars, id = seq_len(nrow(mtcars)))
# Create a linked brush object
lb <- linked_brush(keys = mtcars$id, "red")
# Just the brushed points
selected <- lb$selected
@corynissen
corynissen / bus_stop_map.R
Last active August 29, 2015 14:02
leaflet map using rCharts
library(rCharts)
bus.map <- Leaflet$new()
bus.map$setView(c(40.4739, -88.9719), zoom = 13)
bus.map$tileLayer(provider = 'Stamen.TonerLite')
# Add Data as GeoJSON Layer and Specify Popup and FillColor
bus.map$geoJson(toGeoJSON(tmp.data, lat = 'lat', lon = 'lon'),
onEachFeature = '#! function(feature, layer){
layer.bindPopup(feature.properties.popup)
} !#',
pointToLayer = "#! function(feature, latlng){
@corynissen
corynissen / transform.R
Last active August 29, 2015 14:02
transform df to list for rCharts
library(RColorBrewer)
# max of 12 cats in colorbrewer, gotta add 6 more
colors <- brewer.pal(12, "Paired")
colors <- c(colors, "#050505", "#FAF20F", "#FA28EC", "#24E3CD", "#DAFAD4", "#6B6C6E")
df2 <- df
routes <- unique(df2$route)
df2$color <- colors[match(df2$route, routes)]
df2$popup <- paste0("<p>Pick up time: ", df$pu.time,
"<br>Drop off time: ", df$do.time,
"<br>", df$stop,
@corynissen
corynissen / output.R
Created June 11, 2014 13:02
the dataset ready for mapping
> head(df)
route od pu.time do.time
3 BHS_11.pdf 6:54 AM RAINBOW AVE @ RIDGEPORT AVE 2:33 PM 6:54 AM 2:33 PM
4 BHS_11.pdf 7:02 AM RIDGEPORT AVE @ CLEARWATER AVE 2:36 PM 7:02 AM 2:36 PM
8 BHS_13.pdf 6:48 AM ON MERCER AT LINCOLN 2:44 PM 6:48 AM 2:44 PM
10 BHS_13.pdf 6:49 AM BENJAMIN LN @ SNYDER DR 2:46 PM 6:49 AM 2:46 PM
11 BHS_13.pdf 6:52 AM ON ARCADIA AT FAIRMONT 2:33 PM 6:52 AM 2:33 PM
13 BHS_13.pdf 6:55 AM BROADMOOR DR @ PHEASANT RUN 2:35 PM 6:55 AM 2:35 PM
stop lat lon
3 RAINBOW AVE and RIDGEPORT AVE 40.49903 -88.94384
@corynissen
corynissen / readPDF.R
Created June 11, 2014 12:53
get data from pdf files
library(tm)
pdf <- readPDF(PdftotextOptions = "-layout")
dat <- pdf(elem = list(uri=paste0("data/", file)), language='en', id='id1')
dat <- gsub(' +', ',', dat)
out <- read.csv(textConnection(dat), header=FALSE)
out <- apply(out, 1, function(x)paste(x, collapse=" "))
@corynissen
corynissen / getFiles.R
Created June 11, 2014 12:47
download the bus stop pdf files
library(downloader)
for(link in links){
url1 <- paste0("http://www.district87.org", link)
download(url1, file.path("data", basename(url1)))
}
@corynissen
corynissen / getList.R
Last active September 28, 2016 03:15
Get list of bus stop files
library(XML)
library(httr)
url1 <- "http://www.district87.org/pages/Bloomington_School_District_87/Parents_and_Students/Bus_Routes/Bloomington_High_School"
x <- GET(url1)
text <- content(x, as="text")
doc <- htmlParse(text)
a <- xpathSApply(doc, "//table[@id='fsvItemsTable']/tr")
links <- xpathSApply(a[[1]], "//a/@href")
links <- links[grepl("^/files", links)]