Skip to content

Commit

Permalink
Merge pull request #28 from rzitomer/master
Browse files Browse the repository at this point in the history
Updates to map tab
  • Loading branch information
lyiris22 authored Jan 26, 2019
2 parents 193e321 + 004f6ce commit e9995dd
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions crime-data-app/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ ui <- fluidPage(
sidebarPanel(
sliderInput("year_input", "Select a year",
min = 1975, max = 2014, value = 2000,
width = '100%', sep=""),
selectInput("crime_input", "Select a Crime", crimes_list)
width = '100%', sep="", animate=TRUE),
#selectInput("crime_input", "Select a Crime", crimes_list)
checkboxGroupInput("crime_input",
"Select a Crime",
crimes_list,
selected=c('homs_per_100k','rape_per_100k','rob_per_100k','agg_ass_per_100k')
)
),
# main panel for map
mainPanel(leafletOutput("mymap"))
Expand Down Expand Up @@ -150,27 +155,43 @@ server <- function(input, output) {
agg = mean(agg_ass_per_100k, na.rm = TRUE))
)


#Get the size for the map circles
crime_circles <- reactive (
dat %>%
filter(year == input$year_input) %>%
select(input$crime_input) %>%
mutate(calc = (.[[1]]-mean(.[[1]],na.rm = TRUE))/sd(.[[1]],na.rm=TRUE))
mutate(calc =rowSums(.,na.rm=TRUE)*ifelse(!("rob_per_100k" %in% input$crime_input) & !("agg_ass_per_100k" %in% input$crime_input),
ifelse("rape_per_100k" %in% input$crime_input,8,20),1))
)

labs <- reactive(lapply(seq(nrow(dat%>% filter(year==input$year_input))), function(i) {
z <- dat %>% filter(year==input$year_input)
paste0( '<ul> <b>',z[i, "city"], '</b><li>',
'Total Population: ', prettyNum(round(z[i, "total_pop"]),big.mark = ","),'</li><li>',
'Total Crime (per 100k): ', prettyNum(round(z[i, "violent_per_100k"]),big.mark = ","),'</li><li>',
'Homicide (per 100k): ', prettyNum(round(z[i, "homs_per_100k"]),big.mark = ","),'</li><li>',
'Rape (per 100k): ', prettyNum(round(z[i, "rape_per_100k"]),big.mark = ","),'</li><li>',
'Robbery (per 100k: ', prettyNum(round(z[i, "rob_per_100k"]),big.mark = ","),'</li><li>',
'Assault (per 100k): ', prettyNum(round(z[i, "agg_ass_per_100k"]),big.mark = ","),'</li></ul>'
)
}))


# Map output
output$mymap <- renderLeaflet({
leaflet(dat) %>%
addTiles() %>%
addCircleMarkers(lng = ~lon,
lat = ~lat,
radius = 3*crime_circles()$calc,
radius = .008*crime_circles()$calc,
color = "blue",
fillOpacity = 0.5,
popup = ~city)
fillOpacity = .01,
stroke = FALSE,
label = lapply(labs(), HTML)
)
})


# build the line chart
lines <- reactive(
ggplot() +
Expand Down

0 comments on commit e9995dd

Please sign in to comment.