-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
45 lines (36 loc) · 1.61 KB
/
Copy pathserver.R
File metadata and controls
45 lines (36 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
library(shiny)
colNames = c("EventID", "Date", "Year", "Month", "Day", "SourceActorFull",
"SourceActorEntity", "SourceActorRole", "SourceActorAttribute",
"TargetActorFull", "TargetActorEntity", "TargetActorRole",
"TargetActorAttribute", "EventCode", "EventRootCode", "PentaClass",
"GoldsteinScore", "Issues", "Lat", "Lon", "LocationName", "StateName",
"CountryCode", "SentenceID", "URLs", "NewsSources")
shinyServer(
function(input, output) {
output$numEvents <- renderText({
if (input$goButton == 0)
return()
isolate({
# Download the data for the specified day
fileName <- paste('events.full.', format(as.Date(input$date), "%Y%m%d"), '.txt', sep = "")
zipName <- paste(fileName, '.zip', sep = "")
webName <- paste('http://s3.amazonaws.com/openeventdata/current/', zipName, sep = "")
download.file(webName, zipName)
unzip(zipName)
data <- read.table(fileName, sep = "\t", col.names = colNames, comment.char = "", as.is = TRUE)
# Return the event count
nrow(data)
})
})
output$goldsteinHist <- renderPlot({
if (input$goButton == 0)
return()
isolate({
# Download the data for the specified day
fileName <- paste('events.full.', format(as.Date(input$date), "%Y%m%d"), '.txt', sep = "")
data <- read.table(fileName, sep = "\t", col.names = colNames, comment.char = "", as.is = TRUE)
# Return the event count
hist(data$GoldsteinScore)
})
})
})