-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.R
58 lines (50 loc) · 1.71 KB
/
server.R
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
46
47
48
49
50
51
52
53
54
55
56
57
58
#####################################################################################
#
# Crimes against women in India : A shiny app with choropleth and chart visualizations
# Designed and developed by : Tinniam V Ganesh
# Date : 15 Oct 2015
# File : server.R
#
#####################################################################################
library(shiny)
library(rgeos)
library(maptools)
library(ggplot2)
library(dplyr)
library(stringr)
# Load the India shape files
load(file="./IND_adm/IND_adm1.RData")
ind <- fortify(ind, region = "NAME_1")
# Load the crime data
load(file="./data/crimes.RData")
names(b)
# Set the year
year <- c("2001","2002","2003","2004","2005","2006","2007","2008",
"2009","2010","2011","2012","2013","2014","2015","2016",
"2017","2018")
source("./stateCrime.R", local=TRUE)
states = b$state
# Define server logic required to draw a histogram
shinyServer(function(input, output,session) {
# Update the drop down box with the year. Make the drop down visible after it loads
updateSelectizeInput(session, 'id', choices = year, server = TRUE,selected="2001")
toggle("inputBox")
toggle("id")
#Update the drop down in state wise tab with states
updateSelectizeInput(session, 'state', choices = states, server = TRUE,selected="Assam")
toggle("inputBox1")
toggle("state")
# Display the choropleth map
output$distPlot <- renderPlot({
plotMap(b,input$radio,input$id)
})
# Display the state wise crime plot
output$statePlot <- renderPlot({
print(input$radio1)
print(input$state)
if(input$state==""){
theState <-"Assam"
}
plotCrime(b,input$state,input$radio1)
})
})