Last active
December 11, 2015 18:38
-
-
Save mages/4642963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Markus Gesmann, February 2013 | |
require(googleVis) | |
require(shiny) | |
## Prepare data to be displayed | |
## Load presidential election data by state from 1932 - 2012 | |
library(RCurl) | |
url <- "https://raw.githubusercontent.com/mages/diesunddas/master/Data/US%20Presidential%20Elections.csv" | |
dat <- getURL(url, ssl.verifypeer=0L, followlocation=1L) | |
dat <- read.csv(text=dat) | |
## Add min and max values to the data | |
datminmax = data.frame(state=rep(c("Min", "Max"),21), | |
demVote=rep(c(0, 100),21), | |
year=sort(rep(seq(1932,2012,4),2))) | |
dat <- rbind(dat[,1:3], datminmax) | |
shinyServer(function(input, output) { | |
myYear <- reactive({ | |
input$Year | |
}) | |
output$year <- renderText({ | |
paste("Democratic share of the presidential vote in", myYear()) | |
}) | |
output$gvis <- renderGvis({ | |
myData <- subset(dat, | |
(year > (myYear()-1)) & (year < (myYear()+1))) | |
gvisGeoChart(myData, | |
locationvar="state", colorvar="demVote", | |
options=list(region="US", displayMode="regions", | |
resolution="provinces", | |
width=500, height=400, | |
colorAxis="{colors:['#FFFFFF', '#0000FF']}" | |
)) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(shiny) | |
shinyUI(pageWithSidebar( | |
headerPanel("Example 3: animated geo chart"), | |
sidebarPanel( | |
sliderInput("Year", "Election year to be displayed:", | |
min=1932, max=2012, value=2012, step=4, | |
format="###0",animate=TRUE) | |
), | |
mainPanel( | |
h3(textOutput("year")), | |
htmlOutput("gvis") | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment