Interactive version of the dashboard can be accessed here
For this project, I created an interactive dashboard map that plots the location and magnitude of mass shootings that occured in the U.S. By clicking on the respective circles, a summary of the event can be viewed.
Dashboard is adapted from the “building web applications with Shiny in R” course by Kaelen Medeiros, data is from Mother Jones, and all credit goes to the author for the original instruction.
Code can be found below.
library(shiny)
library(tidyverse)
library(janitor)
library(shinyWidgets)
library(shinythemes)
library(leaflet)
library(lubridate)
mass_shootings = read_csv('mass_shootings.csv')
mass_shootings$date = mdy(mass_shootings$date)
mass_shootings$latitude = as.numeric(mass_shootings$latitude)
mass_shootings$longitude = as.numeric(mass_shootings$longitude)
server <- function(input, output, session) {
rval_mass_shootings <- reactive({
mass_shootings %>%
filter(
date >= input$date_range[1],
date <= input$date_range[2],
fatalities >= input$nb_fatalities
)
})
output$map <- leaflet::renderLeaflet({
rval_mass_shootings() %>%
leaflet() %>%
addTiles() %>%
setView( -98.58, 39.82, zoom = 5) %>%
addTiles() %>%
addCircleMarkers(
popup = ~ summary, radius = ~ fatalities,
fillColor = 'black', color = 'black', weight = 1
)
})
}
ui <- bootstrapPage(
theme = shinythemes::shinytheme('simplex'),
leaflet::leafletOutput('map', height = '100%', width = '100%'),
absolutePanel(top = 10, right = 10, id = 'controls',
sliderInput('nb_fatalities', 'Minimum Fatalities', 1, 40, 10),
dateRangeInput('date_range', 'Select Date', "2010-01-01", "2019-12-01")
),
tags$style(type = "text/css", "
html, body {width:100%;height:100%}
#controls{background-color:white;padding:20px;}
")
)
shinyApp(ui, server)