From 4feb82da05edf8840d3f100cd298bf7bc0332c73 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 24 Oct 2019 10:30:51 -0700 Subject: [PATCH] Updates all files --- .RData | Bin 0 -> 11712346 bytes .Rhistory | 512 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .Rproj.user/944892C3/console06/INDEX001 | 1 + .Rproj.user/944892C3/pcs/files-pane.pper | 9 +++++++++ .Rproj.user/944892C3/pcs/source-pane.pper | 3 +++ .Rproj.user/944892C3/pcs/windowlayoutstate.pper | 14 ++++++++++++++ .Rproj.user/944892C3/pcs/workbench-pane.pper | 6 ++++++ .Rproj.user/944892C3/rmd-outputs | 5 +++++ .Rproj.user/944892C3/saved_source_markers | 1 + .Rproj.user/944892C3/sources/per/t/2DA50A8C | 22 ++++++++++++++++++++++ .Rproj.user/944892C3/sources/per/t/2DA50A8C-contents | 37 +++++++++++++++++++++++++++++++++++++ .Rproj.user/944892C3/sources/per/t/7C20CC79 | 22 ++++++++++++++++++++++ .Rproj.user/944892C3/sources/per/t/7C20CC79-contents | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .Rproj.user/944892C3/sources/per/t/96E31DD3 | 22 ++++++++++++++++++++++ .Rproj.user/944892C3/sources/per/t/96E31DD3-contents | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .Rproj.user/944892C3/sources/per/t/A12A982C | 22 ++++++++++++++++++++++ .Rproj.user/944892C3/sources/per/t/A12A982C-contents | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ .Rproj.user/944892C3/sources/per/t/A8816B8B | 22 ++++++++++++++++++++++ .Rproj.user/944892C3/sources/per/t/A8816B8B-contents | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .Rproj.user/944892C3/sources/per/t/B3E56EC9 | 22 ++++++++++++++++++++++ .Rproj.user/944892C3/sources/per/t/B3E56EC9-contents | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .Rproj.user/944892C3/sources/per/t/D664F6C4 | 22 ++++++++++++++++++++++ .Rproj.user/944892C3/sources/per/t/D664F6C4-contents | 46 ++++++++++++++++++++++++++++++++++++++++++++++ .Rproj.user/944892C3/sources/prop/11F66727 | 5 +++++ .Rproj.user/944892C3/sources/prop/1A88722D | 4 ++++ .Rproj.user/944892C3/sources/prop/31EDA652 | 4 ++++ .Rproj.user/944892C3/sources/prop/340440BD | 4 ++++ .Rproj.user/944892C3/sources/prop/3923804B | 2 ++ .Rproj.user/944892C3/sources/prop/3C947E7E | 4 ++++ .Rproj.user/944892C3/sources/prop/3D6D07B9 | 4 ++++ .Rproj.user/944892C3/sources/prop/3E095C95 | 4 ++++ .Rproj.user/944892C3/sources/prop/43CCD005 | 4 ++++ .Rproj.user/944892C3/sources/prop/49194170 | 4 ++++ .Rproj.user/944892C3/sources/prop/642D5398 | 4 ++++ .Rproj.user/944892C3/sources/prop/6A8E94CA | 4 ++++ .Rproj.user/944892C3/sources/prop/725158E | 4 ++++ .Rproj.user/944892C3/sources/prop/7502090B | 5 +++++ .Rproj.user/944892C3/sources/prop/77A6324 | 4 ++++ .Rproj.user/944892C3/sources/prop/7E86B5E3 | 4 ++++ .Rproj.user/944892C3/sources/prop/87094C22 | 4 ++++ .Rproj.user/944892C3/sources/prop/996C255D | 4 ++++ .Rproj.user/944892C3/sources/prop/9978B5D1 | 4 ++++ .Rproj.user/944892C3/sources/prop/A45D2BB7 | 4 ++++ .Rproj.user/944892C3/sources/prop/BE804CE4 | 4 ++++ .Rproj.user/944892C3/sources/prop/C1D6F94C | 5 +++++ .Rproj.user/944892C3/sources/prop/C4DB5C5E | 5 +++++ .Rproj.user/944892C3/sources/prop/C777DB4A | 4 ++++ .Rproj.user/944892C3/sources/prop/DA893C6A | 4 ++++ .Rproj.user/944892C3/sources/prop/DABAA839 | 5 +++++ .Rproj.user/944892C3/sources/prop/EB7923CA | 4 ++++ .Rproj.user/944892C3/sources/prop/ED446F2C | 5 +++++ .Rproj.user/944892C3/sources/prop/FC40F374 | 5 +++++ .Rproj.user/944892C3/sources/prop/INDEX | 29 +++++++++++++++++++++++++++++ .Rproj.user/shared/notebooks/patch-chunk-names | 0 .Rproj.user/shared/notebooks/paths | 10 ++++++++++ 1. Preprocessing.R | 7 ++++--- 2. SimpleShinyApp.R | 5 +++-- 3. ShinyDashboard.R | 3 +-- 4. UpdatedDashboard.R | 15 ++++++++------- 5. UpdatedDashboard_withTabs.R | 26 ++++++++++++++------------ 6. Final_Dashboard.R | 49 ++++++++++++++++++++++++++++--------------------- 7. Advance.R | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 62 files changed, 1627 insertions(+), 47 deletions(-) create mode 100644 .RData create mode 100644 .Rhistory create mode 100644 .Rproj.user/944892C3/console06/INDEX001 create mode 100644 .Rproj.user/944892C3/pcs/files-pane.pper create mode 100644 .Rproj.user/944892C3/pcs/source-pane.pper create mode 100644 .Rproj.user/944892C3/pcs/windowlayoutstate.pper create mode 100644 .Rproj.user/944892C3/pcs/workbench-pane.pper create mode 100644 .Rproj.user/944892C3/rmd-outputs create mode 100644 .Rproj.user/944892C3/saved_source_markers create mode 100644 .Rproj.user/944892C3/sources/per/t/2DA50A8C create mode 100644 .Rproj.user/944892C3/sources/per/t/2DA50A8C-contents create mode 100644 .Rproj.user/944892C3/sources/per/t/7C20CC79 create mode 100644 .Rproj.user/944892C3/sources/per/t/7C20CC79-contents create mode 100644 .Rproj.user/944892C3/sources/per/t/96E31DD3 create mode 100644 .Rproj.user/944892C3/sources/per/t/96E31DD3-contents create mode 100644 .Rproj.user/944892C3/sources/per/t/A12A982C create mode 100644 .Rproj.user/944892C3/sources/per/t/A12A982C-contents create mode 100644 .Rproj.user/944892C3/sources/per/t/A8816B8B create mode 100644 .Rproj.user/944892C3/sources/per/t/A8816B8B-contents create mode 100644 .Rproj.user/944892C3/sources/per/t/B3E56EC9 create mode 100644 .Rproj.user/944892C3/sources/per/t/B3E56EC9-contents create mode 100644 .Rproj.user/944892C3/sources/per/t/D664F6C4 create mode 100644 .Rproj.user/944892C3/sources/per/t/D664F6C4-contents create mode 100644 .Rproj.user/944892C3/sources/prop/11F66727 create mode 100644 .Rproj.user/944892C3/sources/prop/1A88722D create mode 100644 .Rproj.user/944892C3/sources/prop/31EDA652 create mode 100644 .Rproj.user/944892C3/sources/prop/340440BD create mode 100644 .Rproj.user/944892C3/sources/prop/3923804B create mode 100644 .Rproj.user/944892C3/sources/prop/3C947E7E create mode 100644 .Rproj.user/944892C3/sources/prop/3D6D07B9 create mode 100644 .Rproj.user/944892C3/sources/prop/3E095C95 create mode 100644 .Rproj.user/944892C3/sources/prop/43CCD005 create mode 100644 .Rproj.user/944892C3/sources/prop/49194170 create mode 100644 .Rproj.user/944892C3/sources/prop/642D5398 create mode 100644 .Rproj.user/944892C3/sources/prop/6A8E94CA create mode 100644 .Rproj.user/944892C3/sources/prop/725158E create mode 100644 .Rproj.user/944892C3/sources/prop/7502090B create mode 100644 .Rproj.user/944892C3/sources/prop/77A6324 create mode 100644 .Rproj.user/944892C3/sources/prop/7E86B5E3 create mode 100644 .Rproj.user/944892C3/sources/prop/87094C22 create mode 100644 .Rproj.user/944892C3/sources/prop/996C255D create mode 100644 .Rproj.user/944892C3/sources/prop/9978B5D1 create mode 100644 .Rproj.user/944892C3/sources/prop/A45D2BB7 create mode 100644 .Rproj.user/944892C3/sources/prop/BE804CE4 create mode 100644 .Rproj.user/944892C3/sources/prop/C1D6F94C create mode 100644 .Rproj.user/944892C3/sources/prop/C4DB5C5E create mode 100644 .Rproj.user/944892C3/sources/prop/C777DB4A create mode 100644 .Rproj.user/944892C3/sources/prop/DA893C6A create mode 100644 .Rproj.user/944892C3/sources/prop/DABAA839 create mode 100644 .Rproj.user/944892C3/sources/prop/EB7923CA create mode 100644 .Rproj.user/944892C3/sources/prop/ED446F2C create mode 100644 .Rproj.user/944892C3/sources/prop/FC40F374 create mode 100644 .Rproj.user/944892C3/sources/prop/INDEX create mode 100644 .Rproj.user/shared/notebooks/patch-chunk-names create mode 100644 .Rproj.user/shared/notebooks/paths create mode 100644 7. Advance.R diff --git a/.RData b/.RData new file mode 100644 index 0000000..28fb4cb Binary files /dev/null and b/.RData differ diff --git a/.Rhistory b/.Rhistory new file mode 100644 index 0000000..fd621d3 --- /dev/null +++ b/.Rhistory @@ -0,0 +1,512 @@ +output$perhour <- renderPlot({ +df_fil <- filter(df, YEAR == input$year) +df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) +ggplot(data = df_fil_grp,aes(x = df_fil_grp$HOUR)) + geom_bar(fill="green") + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() +}) +#Defining the timeseries plot +output$timeseries <- renderPlot({ +df_fil <- filter(df, YEAR == input$year) +df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) +ggplot(data = df_fil_grp, aes(x = df_fil_grp$OCCURRED_ON_DATE))+ xlab("Date") + ylab("Number of Crimes") + geom_freqpoly(colour="purple") +}) +#Defining the newly created stacked plot +output$stacked <- renderPlot({ +df_fil <- filter(df, YEAR == input$year) +df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) +df_fil_grp %>% filter(DISTRICT %in% (df_fil_grp %>% count(DISTRICT) %>% arrange(-n) %>% head(7) %>% pull(DISTRICT)), +OFFENSE_DESCRIPTION %in% (df_fil_grp %>% count(OFFENSE_DESCRIPTION) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_DESCRIPTION))) %>% +ggplot(aes(DISTRICT, fill = OFFENSE_DESCRIPTION))+ +geom_bar(position = "fill") +}) +output$mymap <- renderLeaflet({ +df_fil <- filter(df, YEAR == input$year) +df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) +dm <- data.frame(latitude = df_fil_grp$Lat, longitude = df_fil_grp$Long) +leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% +addMarkers( +clusterOptions = markerClusterOptions() +) %>% setView(-71.1, 42.32, zoom = 12) +}) +output$table <- renderDataTable( +filter(filter(df, YEAR == input$year), OFFENSE_CODE_GROUP == input$offense), +options = list(scrollX = TRUE) +) +} +## Project Boston Crimes: Building Our App +shinyApp(ui, server) +#Defining the body of the dashboard +body <- dashboardBody( +#The body consists of a row-based layout with a single fluid row +fluidRow( +#Defining the output within a box +box(plotOutput("barplot")) +) +) +#Defining the header object +header <- dashboardHeader(title = "Boston Police") +#Defining the sidebard object +sidebar <- dashboardSidebar( +radioButtons("year", "Select Year: ", +c("2015" = "2015", +"2016" = "2016", +"2017" = "2017", +"2018" = "2018", +"2019" = "2019")) +) +#Defining our ui object with a dashboardPage template +ui <- dashboardPage(header, sidebar, body) +server <- function(input, output) { +output$barplot <- renderPlot({ +df_fil <- filter(df, YEAR == input$year) +ggplot(data = df_fil, aes(x = df_fil$HOUR)) + geom_bar() + xlab("Hour") + ylab("Number of Crimes") + theme_economist() +}) +} +shinyApp(ui, server) +library(ggthemes) +install.packages('ggthemes') +library(ggthemes) +server <- function(input, output) { +output$barplot <- renderPlot({ +df_fil <- filter(df, YEAR == input$year) +ggplot(data = df_fil, aes(x = df_fil$HOUR)) + geom_bar() + xlab("Hour") + ylab("Number of Crimes") + theme_economist() +}) +} +shinyApp(ui, server) +server <- function(input, output) { +output$barplot <- renderPlot({ +df_fil <- filter(df, YEAR == input$year) +ggplot(data = df_fil, aes(x = df_fil$HOUR)) + geom_bar() + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() +}) +} +shinyApp(ui, server) +?radioButtons +clc +library(tidyverse) +library(lubridate) +library(dplyr) +library(ggplot2) +library(leaflet) +library(shiny) +library(shinydashboard) +df <- read.csv(file = "crime.csv", header = TRUE, sep=",") +#remove missing values +df <- na.omit(df) +#Preprocessing +df$YEAR <- as.factor(df$YEAR) +df$HOUR <- as.factor(df$HOUR) +df$MONTH <- as.factor(df$MONTH) +df$OCCURRED_ON_DATE <- as.POSIXct(df$OCCURRED_ON_DATE, format = "%Y-%m-%d %H:%M:%OS") +row1 <- fluidRow( +tabBox( +title = "Crime Frequency", +id = "tabset1", height = "250px", +tabPanel("Per Month", plotOutput("permonth")), +tabPanel("Per Weekday", plotOutput("perday")), +tabPanel("Per Hour", plotOutput("perhour")) +) +,box(title = "Map View", solidHeader = TRUE +,collapsible = TRUE, leafletOutput("mymap")) +) +#Creating another fluid row +row2 <- fluidRow( +box(title = "Stacked Plot", solidHeader = TRUE +,collapsible = TRUE, plotOutput("stacked")) +,box(title = "Timeseries Plot", solidHeader = TRUE +,collapsible = TRUE, plotOutput("timeseries")) +) +#Adding components to body: +body <- dashboardBody(row1, row2) +## Project Boston Crimes: UI - Header & Sidebars +header <- dashboardHeader(title = "Boston Crime Dataset") +sidebar <- dashboardSidebar( +radioButtons("year", "Select Year: ", +c("2015" = "2015", +"2016" = "2016", +"2017" = "2017", +"2018" = "2018", +"2019" = "2019")), +selectInput("offense", +"Offense Group:", +c(unique(as.character(df$OFFENSE_CODE_GROUP[1:10])))) +) +#Adding all components to UI: +ui <- dashboardPage(header, sidebar, body) +## Project Boston Crimes: Server +server <- function(input, output) { +#creating a reactive object +filtered <- reactive({ +filter(filter(df, YEAR == input$year), OFFENSE_CODE_GROUP == input$offense) +}) +#creating the plotOutput content +output$permonth <- renderPlot({ +ggplot(data = filtered, aes(x = filtered$MONTH)) + geom_bar(fill="steelblue") + xlab("Month") + ylab("Number of Crimes") + theme_minimal() +}) +output$perday <- renderPlot({ +ggplot(data = filtered, aes(x = filtered$DAY_OF_WEEK)) + geom_bar(fill="red") + xlab("Day of Week") + ylab("Number of Crimes") + theme_minimal() +}) +output$perhour <- renderPlot({ +ggplot(data = filtered,aes(x = filtered$HOUR)) + geom_bar(fill="green") + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() +}) +#Defining the timeseries plot +output$timeseries <- renderPlot({ +ggplot(data = filtered, aes(x = filtered$OCCURRED_ON_DATE))+ xlab("Date") + ylab("Number of Crimes") + geom_freqpoly(colour="purple") +}) +#Defining the newly created stacked plot +output$stacked <- renderPlot({ +filtered %>% filter(DISTRICT %in% (filtered %>% count(DISTRICT) %>% arrange(-n) %>% head(7) %>% pull(DISTRICT)), +OFFENSE_DESCRIPTION %in% (filtered %>% count(OFFENSE_DESCRIPTION) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_DESCRIPTION))) %>% +ggplot(aes(DISTRICT, fill = OFFENSE_DESCRIPTION))+ +geom_bar(position = "fill") +}) +output$mymap <- renderLeaflet({ +dm <- data.frame(latitude = filtered$Lat, longitude = filtered$Long) +leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% +addMarkers( +clusterOptions = markerClusterOptions() +) %>% setView(-71.1, 42.32, zoom = 12) +}) +} +## Project Boston Crimes: Building Our App +shinyApp(ui, server) +## Project Boston Crimes: Server +server <- function(input, output) { +#creating a reactive object +filtered <- reactive({ +filter(filter(df, YEAR == input$year), OFFENSE_CODE_GROUP == input$offense) +}) +#creating the plotOutput content +output$permonth <- renderPlot({ +ggplot(data = filtered(), aes(x = filtered()$MONTH)) + geom_bar(fill="steelblue") + xlab("Month") + ylab("Number of Crimes") + theme_minimal() +}) +output$perday <- renderPlot({ +ggplot(data = filtered, aes(x = filtered$DAY_OF_WEEK)) + geom_bar(fill="red") + xlab("Day of Week") + ylab("Number of Crimes") + theme_minimal() +}) +output$perhour <- renderPlot({ +ggplot(data = filtered,aes(x = filtered$HOUR)) + geom_bar(fill="green") + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() +}) +#Defining the timeseries plot +output$timeseries <- renderPlot({ +ggplot(data = filtered, aes(x = filtered$OCCURRED_ON_DATE))+ xlab("Date") + ylab("Number of Crimes") + geom_freqpoly(colour="purple") +}) +#Defining the newly created stacked plot +output$stacked <- renderPlot({ +filtered %>% filter(DISTRICT %in% (filtered %>% count(DISTRICT) %>% arrange(-n) %>% head(7) %>% pull(DISTRICT)), +OFFENSE_DESCRIPTION %in% (filtered %>% count(OFFENSE_DESCRIPTION) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_DESCRIPTION))) %>% +ggplot(aes(DISTRICT, fill = OFFENSE_DESCRIPTION))+ +geom_bar(position = "fill") +}) +output$mymap <- renderLeaflet({ +dm <- data.frame(latitude = filtered$Lat, longitude = filtered$Long) +leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% +addMarkers( +clusterOptions = markerClusterOptions() +) %>% setView(-71.1, 42.32, zoom = 12) +}) +} +## Project Boston Crimes: Building Our App +shinyApp(ui, server) +## Project Boston Crimes: Server +server <- function(input, output) { +#creating a reactive object +filtered <- reactive({ +filter(filter(df, YEAR == input$year), OFFENSE_CODE_GROUP == input$offense) +}) +#creating the plotOutput content +output$permonth <- renderPlot({ +ggplot(data = filtered(), aes(x = filtered()$MONTH)) + geom_bar(fill="steelblue") + xlab("Month") + ylab("Number of Crimes") + theme_minimal() +}) +output$perday <- renderPlot({ +ggplot(data = filtered(), aes(x = filtered()$DAY_OF_WEEK)) + geom_bar(fill="red") + xlab("Day of Week") + ylab("Number of Crimes") + theme_minimal() +}) +output$perhour <- renderPlot({ +ggplot(data = filtered(),aes(x = filtered()$HOUR)) + geom_bar(fill="green") + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() +}) +#Defining the timeseries plot +output$timeseries <- renderPlot({ +ggplot(data = filtered(), aes(x = filtered()$OCCURRED_ON_DATE))+ xlab("Date") + ylab("Number of Crimes") + geom_freqpoly(colour="purple") +}) +#Defining the newly created stacked plot +output$stacked <- renderPlot({ +filtered() %>% filter(DISTRICT %in% (filtered() %>% count(DISTRICT) %>% arrange(-n) %>% head(7) %>% pull(DISTRICT)), +OFFENSE_DESCRIPTION %in% (filtered() %>% count(OFFENSE_DESCRIPTION) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_DESCRIPTION))) %>% +ggplot(aes(DISTRICT, fill = OFFENSE_DESCRIPTION))+ +geom_bar(position = "fill") +}) +output$mymap <- renderLeaflet({ +dm <- data.frame(latitude = filtered()$Lat, longitude = filtered()$Long) +leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% +addMarkers( +clusterOptions = markerClusterOptions() +) %>% setView(-71.1, 42.32, zoom = 12) +}) +} +## Project Boston Crimes: Building Our App +shinyApp(ui, server) +runApp('7. Advance.R') +#importing following packages +library(tidyverse) +library(lubridate) +library(dplyr) +library(ggplot2) +library(leaflet) +#importing data file 'crime.csv' +df <- read.csv(file = "crime.csv", header = TRUE, sep=",") +#view first few rows +head(df) +#remove missing values +df <- na.omit(df) +#view number of rows and columns +dim(df) +#view data types +str(df) +#Preprocessing +df$YEAR <- as.factor(df$YEAR) +df$HOUR <- as.factor(df$HOUR) +df$MONTH <- as.factor(df$MONTH) +df$OCCURRED_ON_DATE <- as.POSIXct(df$OCCURRED_ON_DATE, format = "%Y-%m-%d %H:%M:%OS") +str(df) +#importing shiny library +library(shiny) +ui <- basicPage("My first Shiny App") +server <- function(input, output){} +shinyApp(ui = ui, server = server) +#Creating a UI object with a fluidPage layout +ui <- fluidPage( +#setting radio buttons input in the UI +radioButtons("year", "Select Year: ", +c("2015" = "2015", +"2016" = "2016", +"2017" = "2017", +"2018" = "2018", +"2019" = "2019")), +#setting an output in form of plot +plotOutput("barplot") +) +#Creating the server object +server <- function(input, output){ +#defining the barplot introduced in the UI +output$barplot <- renderPlot({ +#filtering data with respect to input from radio buttons using 'year' ID +df_fil <- filter(df, YEAR == input$year) +#defining the barplot using ggplot2 +ggplot(data = df_fil, aes(x = df_fil$HOUR)) + geom_bar() + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() +}) +} +shinyApp(ui = ui, server = server) +#Building a simple Shiny Dashboard +library(shinydashboard) +#Defining the body of the dashboard +body <- dashboardBody( +#The body consists of a row-based layout with a single fluid row +fluidRow( +#Defining the output within a box +box(plotOutput("barplot")) +) +) +#Defining the header object +header <- dashboardHeader(title = "Boston Police") +#Defining the sidebard object +sidebar <- dashboardSidebar( +radioButtons("year", "Select Year: ", +c("2015" = "2015", +"2016" = "2016", +"2017" = "2017", +"2018" = "2018", +"2019" = "2019")) +) +#Defining our ui object with a dashboardPage template +ui <- dashboardPage(header, sidebar, body) +server <- function(input, output) { +output$barplot <- renderPlot({ +df_fil <- filter(df, YEAR == input$year) +ggplot(data = df_fil, aes(x = df_fil$HOUR)) + geom_bar() + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() +}) +} +shinyApp(ui, server) +body <- dashboardBody( +fluidRow( +box(title = "Crime Frequency", solidHeader = TRUE +,collapsible = TRUE, plotOutput("barplot")), +#Adding another box to our fluidRow +box(title = "Map View", solidHeader = TRUE +,collapsible = TRUE, leafletOutput("mapview")) +) +) +header <- dashboardHeader(title = "Boston Police") +sidebar <- dashboardSidebar( +radioButtons("year", "Select Year: ", +c("2015" = "2015", +"2016" = "2016", +"2017" = "2017", +"2018" = "2018", +"2019" = "2019")), +#Adding a dropdown menu within the sidebar +selectInput("offense", +"Offense Group:", +c(unique(as.character(df$OFFENSE_CODE_GROUP[1:10])))) +) +ui <- dashboardPage(header, sidebar, body) +server <- function(input, output) { +output$barplot <- renderPlot({ +df_fil <- filter(df, YEAR == input$year) +df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) +ggplot(data = df_fil_grp, aes(x = df_fil_grp$HOUR)) + geom_bar() + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() +}) +#Defining our 'mapview' plot declared in the UI above +output$mapview <- renderLeaflet({ +df_fil <- filter(df, YEAR == input$year) +df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) +dm <- data.frame(latitude = df_fil_grp$Lat, longitude = df_fil_grp$Long) +leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% +addMarkers( +clusterOptions = markerClusterOptions() +) %>% setView(-71.1, 42.32, zoom = 12) +}) +} +shinyApp(ui = ui, server = server) +row <- fluidRow( +#tabBox layout with multiple tab panels. Each panel has a plot Output +tabBox( +title = "Crime Frequency", +id = "tabset1", height = "250px", +tabPanel("Per Month", plotOutput("permonth")), +tabPanel("Per Weekday", plotOutput("perday")), +tabPanel("Per Hour", plotOutput("perhour")) +) +,box(title = "Map View", solidHeader = TRUE +,collapsible = TRUE, leafletOutput("mymap")) +) +#Adding components to body: +body <- dashboardBody(row) +header <- dashboardHeader(title = "Boston Crime Dataset") +sidebar <- dashboardSidebar( +radioButtons("year", "Select Year: ", +c("2015" = "2015", +"2016" = "2016", +"2017" = "2017", +"2018" = "2018", +"2019" = "2019")), +selectInput("offense", +"Offense Group:", +c(unique(as.character(df$OFFENSE_CODE_GROUP[1:10])))) +) +#Adding all components to UI: +ui <- dashboardPage(header, sidebar, body) +## Project Boston Crimes: Server +server <- function(input, output) { +#creating the plotOutput content +output$permonth <- renderPlot({ +df_fil <- filter(df, YEAR == input$year) +df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) +ggplot(data = df_fil_grp,aes(x = df_fil_grp$MONTH)) + geom_bar(fill="steelblue") + xlab("Month") + ylab("Number of Crimes") + theme_minimal() +}) +output$perday <- renderPlot({ +df_fil <- filter(df, YEAR == input$year) +df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) +ggplot(data = df_fil_grp,aes(x = df_fil_grp$DAY_OF_WEEK)) + geom_bar(fill="red") + xlab("Day of Week") + ylab("Number of Crimes") + theme_minimal() +}) +output$perhour <- renderPlot({ +df_fil <- filter(df, YEAR == input$year) +df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) +ggplot(data = df_fil_grp,aes(x = df_fil_grp$HOUR)) + geom_bar(fill="purple") + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() +}) +output$mymap <- renderLeaflet({ +df_fil <- filter(df, YEAR == input$year) +df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) +dm <- data.frame(latitude = df_fil_grp$Lat, longitude = df_fil_grp$Long) +leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% +addMarkers( +clusterOptions = markerClusterOptions() +) %>% setView(-71.1, 42.32, zoom = 12) +}) +} +## Project Boston Crimes: Building Our App +shinyApp(ui, server) +library(tidyverse) +library(lubridate) +library(dplyr) +library(ggplot2) +library(leaflet) +library(shiny) +library(shinydashboard) +df <- read.csv(file = "crime.csv", header = TRUE, sep=",") +#remove missing values +df <- na.omit(df) +#Preprocessing +df$YEAR <- as.factor(df$YEAR) +df$HOUR <- as.factor(df$HOUR) +df$MONTH <- as.factor(df$MONTH) +df$OCCURRED_ON_DATE <- as.POSIXct(df$OCCURRED_ON_DATE, format = "%Y-%m-%d %H:%M:%OS") +row1 <- fluidRow( +tabBox( +title = "Crime Frequency", +id = "tabset1", height = "250px", +tabPanel("Per Month", plotOutput("permonth")), +tabPanel("Per Weekday", plotOutput("perday")), +tabPanel("Per Hour", plotOutput("perhour")) +) +,box(title = "Map View", solidHeader = TRUE +,collapsible = TRUE, leafletOutput("mymap")) +) +#Creating another fluid row +row2 <- fluidRow( +box(title = "Stacked Plot", solidHeader = TRUE +,collapsible = TRUE, plotOutput("stacked")) +,box(title = "Timeseries Plot", solidHeader = TRUE +,collapsible = TRUE, plotOutput("timeseries")) +) +#Adding components to body: +body <- dashboardBody(row1, row2) +## Project Boston Crimes: UI - Header & Sidebars +header <- dashboardHeader(title = "Boston Crime Dataset") +sidebar <- dashboardSidebar( +radioButtons("year", "Select Year: ", +c("2015" = "2015", +"2016" = "2016", +"2017" = "2017", +"2018" = "2018", +"2019" = "2019")), +selectInput("offense", +"Offense Group:", +c(unique(as.character(df$OFFENSE_CODE_GROUP[1:10])))) +) +#Adding all components to UI: +ui <- dashboardPage(header, sidebar, body) +## Project Boston Crimes: Server +server <- function(input, output) { +#creating a reactive object +filtered <- reactive({ +filter(filter(df, YEAR == input$year), OFFENSE_CODE_GROUP == input$offense) +}) +#creating the plotOutput content +output$permonth <- renderPlot({ +ggplot(data = filtered(), aes(x = filtered()$MONTH)) + geom_bar(fill="steelblue") + xlab("Month") + ylab("Number of Crimes") + theme_minimal() +}) +output$perday <- renderPlot({ +ggplot(data = filtered(), aes(x = filtered()$DAY_OF_WEEK)) + geom_bar(fill="red") + xlab("Day of Week") + ylab("Number of Crimes") + theme_minimal() +}) +output$perhour <- renderPlot({ +ggplot(data = filtered(),aes(x = filtered()$HOUR)) + geom_bar(fill="green") + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() +}) +#Defining the timeseries plot +output$timeseries <- renderPlot({ +ggplot(data = filtered(), aes(x = filtered()$OCCURRED_ON_DATE))+ xlab("Date") + ylab("Number of Crimes") + geom_freqpoly(colour="purple") +}) +#Defining the newly created stacked plot +output$stacked <- renderPlot({ +filtered() %>% filter(DISTRICT %in% (filtered() %>% count(DISTRICT) %>% arrange(-n) %>% head(7) %>% pull(DISTRICT)), +OFFENSE_DESCRIPTION %in% (filtered() %>% count(OFFENSE_DESCRIPTION) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_DESCRIPTION))) %>% +ggplot(aes(DISTRICT, fill = OFFENSE_DESCRIPTION))+ +geom_bar(position = "fill") +}) +output$mymap <- renderLeaflet({ +dm <- data.frame(latitude = filtered()$Lat, longitude = filtered()$Long) +leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% +addMarkers( +clusterOptions = markerClusterOptions() +) %>% setView(-71.1, 42.32, zoom = 12) +}) +} +## Project Boston Crimes: Building Our App +shinyApp(ui, server) +runApp('7. Advance.R') diff --git a/.Rproj.user/944892C3/console06/INDEX001 b/.Rproj.user/944892C3/console06/INDEX001 new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/.Rproj.user/944892C3/console06/INDEX001 @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/.Rproj.user/944892C3/pcs/files-pane.pper b/.Rproj.user/944892C3/pcs/files-pane.pper new file mode 100644 index 0000000..bab7903 --- /dev/null +++ b/.Rproj.user/944892C3/pcs/files-pane.pper @@ -0,0 +1,9 @@ +{ + "path" : "C:/Users/Paklap.pk/Desktop/4th Webinar/Interactive_Dashboards", + "sortOrder" : [ + { + "ascending" : true, + "columnIndex" : 2 + } + ] +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/pcs/source-pane.pper b/.Rproj.user/944892C3/pcs/source-pane.pper new file mode 100644 index 0000000..d3d70fa --- /dev/null +++ b/.Rproj.user/944892C3/pcs/source-pane.pper @@ -0,0 +1,3 @@ +{ + "activeTab" : 6 +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/pcs/windowlayoutstate.pper b/.Rproj.user/944892C3/pcs/windowlayoutstate.pper new file mode 100644 index 0000000..71363d8 --- /dev/null +++ b/.Rproj.user/944892C3/pcs/windowlayoutstate.pper @@ -0,0 +1,14 @@ +{ + "left" : { + "panelheight" : 848, + "splitterpos" : 209, + "topwindowstate" : "NORMAL", + "windowheight" : 887 + }, + "right" : { + "panelheight" : 848, + "splitterpos" : 532, + "topwindowstate" : "NORMAL", + "windowheight" : 887 + } +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/pcs/workbench-pane.pper b/.Rproj.user/944892C3/pcs/workbench-pane.pper new file mode 100644 index 0000000..0e24b84 --- /dev/null +++ b/.Rproj.user/944892C3/pcs/workbench-pane.pper @@ -0,0 +1,6 @@ +{ + "TabSet1" : 0, + "TabSet2" : 0, + "TabZoom" : { + } +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/rmd-outputs b/.Rproj.user/944892C3/rmd-outputs new file mode 100644 index 0000000..3f2ff2d --- /dev/null +++ b/.Rproj.user/944892C3/rmd-outputs @@ -0,0 +1,5 @@ + + + + + diff --git a/.Rproj.user/944892C3/saved_source_markers b/.Rproj.user/944892C3/saved_source_markers new file mode 100644 index 0000000..2b1bef1 --- /dev/null +++ b/.Rproj.user/944892C3/saved_source_markers @@ -0,0 +1 @@ +{"active_set":"","sets":[]} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/per/t/2DA50A8C b/.Rproj.user/944892C3/sources/per/t/2DA50A8C new file mode 100644 index 0000000..0d4d97b --- /dev/null +++ b/.Rproj.user/944892C3/sources/per/t/2DA50A8C @@ -0,0 +1,22 @@ +{ + "collab_server" : "", + "contents" : "", + "created" : 1571850946504.000, + "dirty" : false, + "encoding" : "UTF-8", + "folds" : "", + "hash" : "748450125", + "id" : "2DA50A8C", + "lastKnownWriteTime" : 1571926355, + "last_content_update" : 1571926355961, + "path" : "C:/Users/Paklap.pk/Desktop/4th Webinar/Interactive_Dashboards/2. SimpleShinyApp.R", + "project_path" : "2. SimpleShinyApp.R", + "properties" : { + "cursorPosition" : "36,0", + "scrollLine" : "3" + }, + "relative_order" : 2, + "source_on_save" : false, + "source_window" : "", + "type" : "r_source" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/per/t/2DA50A8C-contents b/.Rproj.user/944892C3/sources/per/t/2DA50A8C-contents new file mode 100644 index 0000000..e7e247f --- /dev/null +++ b/.Rproj.user/944892C3/sources/per/t/2DA50A8C-contents @@ -0,0 +1,37 @@ + +#Building a simple Shiny App with an input and an output plot + +#Creating a UI object with a fluidPage layout +ui <- fluidPage( + + #setting radio buttons input in the UI + radioButtons("year", "Select Year: ", + c("2015" = "2015", + "2016" = "2016", + "2017" = "2017", + "2018" = "2018", + "2019" = "2019")), + + + #setting an output in form of plot + plotOutput("barplot") + +) + +#Creating the server object +server <- function(input, output){ + + #defining the barplot introduced in the UI + output$barplot <- renderPlot({ + + #filtering data with respect to input from radio buttons using 'year' ID + df_fil <- filter(df, YEAR == input$year) + #defining the barplot using ggplot2 + ggplot(data = df_fil, aes(x = df_fil$HOUR)) + geom_bar() + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() + + }) +} + + +shinyApp(ui = ui, server = server) + diff --git a/.Rproj.user/944892C3/sources/per/t/7C20CC79 b/.Rproj.user/944892C3/sources/per/t/7C20CC79 new file mode 100644 index 0000000..fd2de67 --- /dev/null +++ b/.Rproj.user/944892C3/sources/per/t/7C20CC79 @@ -0,0 +1,22 @@ +{ + "collab_server" : "", + "contents" : "", + "created" : 1571853125252.000, + "dirty" : false, + "encoding" : "UTF-8", + "folds" : "", + "hash" : "978112177", + "id" : "7C20CC79", + "lastKnownWriteTime" : 1571936278, + "last_content_update" : 1571936278476, + "path" : "C:/Users/Paklap.pk/Desktop/4th Webinar/Interactive_Dashboards/6. Final_Dashboard.R", + "project_path" : "6. Final_Dashboard.R", + "properties" : { + "cursorPosition" : "130,0", + "scrollLine" : "97" + }, + "relative_order" : 6, + "source_on_save" : false, + "source_window" : "", + "type" : "r_source" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/per/t/7C20CC79-contents b/.Rproj.user/944892C3/sources/per/t/7C20CC79-contents new file mode 100644 index 0000000..c8db850 --- /dev/null +++ b/.Rproj.user/944892C3/sources/per/t/7C20CC79-contents @@ -0,0 +1,130 @@ +library(tidyverse) +library(lubridate) +library(dplyr) +library(ggplot2) +library(leaflet) +library(shiny) +library(shinydashboard) + +df <- read.csv(file = "crime.csv", header = TRUE, sep=",") + +#remove missing values +df <- na.omit(df) + +#Preprocessing +df$YEAR <- as.factor(df$YEAR) +df$HOUR <- as.factor(df$HOUR) +df$MONTH <- as.factor(df$MONTH) +df$OCCURRED_ON_DATE <- as.POSIXct(df$OCCURRED_ON_DATE, format = "%Y-%m-%d %H:%M:%OS") + + + + + +row1 <- fluidRow( + + tabBox( + + title = "Crime Frequency", + id = "tabset1", height = "250px", + + tabPanel("Per Month", plotOutput("permonth")), + tabPanel("Per Weekday", plotOutput("perday")), + tabPanel("Per Hour", plotOutput("perhour")) + ) + + ,box(title = "Map View", solidHeader = TRUE + ,collapsible = TRUE, leafletOutput("mymap")) + +) + +#Creating another fluid row +row2 <- fluidRow( + box(title = "Stacked Plot", solidHeader = TRUE + ,collapsible = TRUE, plotOutput("stacked")) + + ,box(title = "Timeseries Plot", solidHeader = TRUE + ,collapsible = TRUE, plotOutput("timeseries")) +) + + +#Adding components to body: +body <- dashboardBody(row1, row2) + + + +## Project Boston Crimes: UI - Header & Sidebars +header <- dashboardHeader(title = "Boston Crime Dataset") + +sidebar <- dashboardSidebar( + radioButtons("year", "Select Year: ", + c("2015" = "2015", + "2016" = "2016", + "2017" = "2017", + "2018" = "2018", + "2019" = "2019")), + + selectInput("offense", + "Offense Group:", + c(unique(as.character(df$OFFENSE_CODE_GROUP[1:10])))) + +) + +#Adding all components to UI: +ui <- dashboardPage(header, sidebar, body) + + + +## Project Boston Crimes: Server +server <- function(input, output) { + + #creating a reactive object + filtered <- reactive({ + filter(filter(df, YEAR == input$year), OFFENSE_CODE_GROUP == input$offense) + }) + + #creating the plotOutput content + output$permonth <- renderPlot({ + ggplot(data = filtered(), aes(x = filtered()$MONTH)) + geom_bar(fill="steelblue") + xlab("Month") + ylab("Number of Crimes") + theme_minimal() + }) + + output$perday <- renderPlot({ + ggplot(data = filtered(), aes(x = filtered()$DAY_OF_WEEK)) + geom_bar(fill="red") + xlab("Day of Week") + ylab("Number of Crimes") + theme_minimal() + }) + + output$perhour <- renderPlot({ + ggplot(data = filtered(),aes(x = filtered()$HOUR)) + geom_bar(fill="green") + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() + }) + + #Defining the timeseries plot + output$timeseries <- renderPlot({ + + ggplot(data = filtered(), aes(x = filtered()$OCCURRED_ON_DATE))+ xlab("Date") + ylab("Number of Crimes") + geom_freqpoly(colour="purple") + }) + + #Defining the newly created stacked plot + output$stacked <- renderPlot({ + + filtered() %>% filter(DISTRICT %in% (filtered() %>% count(DISTRICT) %>% arrange(-n) %>% head(7) %>% pull(DISTRICT)), + OFFENSE_DESCRIPTION %in% (filtered() %>% count(OFFENSE_DESCRIPTION) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_DESCRIPTION))) %>% + ggplot(aes(DISTRICT, fill = OFFENSE_DESCRIPTION))+ + geom_bar(position = "fill") + }) + + output$mymap <- renderLeaflet({ + + dm <- data.frame(latitude = filtered()$Lat, longitude = filtered()$Long) + + leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% + addMarkers( + clusterOptions = markerClusterOptions() + ) %>% setView(-71.1, 42.32, zoom = 12) + + }) + +} + + + +## Project Boston Crimes: Building Our App +shinyApp(ui, server) diff --git a/.Rproj.user/944892C3/sources/per/t/96E31DD3 b/.Rproj.user/944892C3/sources/per/t/96E31DD3 new file mode 100644 index 0000000..cb0a787 --- /dev/null +++ b/.Rproj.user/944892C3/sources/per/t/96E31DD3 @@ -0,0 +1,22 @@ +{ + "collab_server" : "", + "contents" : "", + "created" : 1571852791181.000, + "dirty" : false, + "encoding" : "UTF-8", + "folds" : "", + "hash" : "2214789430", + "id" : "96E31DD3", + "lastKnownWriteTime" : 1571920520, + "last_content_update" : 1571920520196, + "path" : "C:/Users/Paklap.pk/Desktop/4th Webinar/Interactive_Dashboards/5. UpdatedDashboard_withTabs.R", + "project_path" : "5. UpdatedDashboard_withTabs.R", + "properties" : { + "cursorPosition" : "82,0", + "scrollLine" : "49" + }, + "relative_order" : 5, + "source_on_save" : false, + "source_window" : "", + "type" : "r_source" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/per/t/96E31DD3-contents b/.Rproj.user/944892C3/sources/per/t/96E31DD3-contents new file mode 100644 index 0000000..a564bcd --- /dev/null +++ b/.Rproj.user/944892C3/sources/per/t/96E31DD3-contents @@ -0,0 +1,82 @@ + +row <- fluidRow( + + #tabBox layout with multiple tab panels. Each panel has a plot Output + tabBox( + title = "Crime Frequency", + id = "tabset1", height = "250px", + tabPanel("Per Month", plotOutput("permonth")), + tabPanel("Per Weekday", plotOutput("perday")), + tabPanel("Per Hour", plotOutput("perhour")) + ) + + ,box(title = "Map View", solidHeader = TRUE + ,collapsible = TRUE, leafletOutput("mymap")) +) + + +#Adding components to body: +body <- dashboardBody(row) + + +header <- dashboardHeader(title = "Boston Crime Dataset") + +sidebar <- dashboardSidebar( + radioButtons("year", "Select Year: ", + c("2015" = "2015", + "2016" = "2016", + "2017" = "2017", + "2018" = "2018", + "2019" = "2019")), + + selectInput("offense", + "Offense Group:", + c(unique(as.character(df$OFFENSE_CODE_GROUP[1:10])))) + +) + +#Adding all components to UI: +ui <- dashboardPage(header, sidebar, body) + + + +## Project Boston Crimes: Server +server <- function(input, output) { + + #creating the plotOutput content + output$permonth <- renderPlot({ + df_fil <- filter(df, YEAR == input$year) + df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) + ggplot(data = df_fil_grp,aes(x = df_fil_grp$MONTH)) + geom_bar(fill="steelblue") + xlab("Month") + ylab("Number of Crimes") + theme_minimal() + }) + + output$perday <- renderPlot({ + df_fil <- filter(df, YEAR == input$year) + df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) + ggplot(data = df_fil_grp,aes(x = df_fil_grp$DAY_OF_WEEK)) + geom_bar(fill="red") + xlab("Day of Week") + ylab("Number of Crimes") + theme_minimal() + }) + + output$perhour <- renderPlot({ + df_fil <- filter(df, YEAR == input$year) + df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) + ggplot(data = df_fil_grp,aes(x = df_fil_grp$HOUR)) + geom_bar(fill="purple") + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() + }) + + + output$mymap <- renderLeaflet({ + + df_fil <- filter(df, YEAR == input$year) + df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) + dm <- data.frame(latitude = df_fil_grp$Lat, longitude = df_fil_grp$Long) + + leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% + addMarkers( + clusterOptions = markerClusterOptions() + ) %>% setView(-71.1, 42.32, zoom = 12) + + }) +} + + +## Project Boston Crimes: Building Our App +shinyApp(ui, server) diff --git a/.Rproj.user/944892C3/sources/per/t/A12A982C b/.Rproj.user/944892C3/sources/per/t/A12A982C new file mode 100644 index 0000000..2e96d0b --- /dev/null +++ b/.Rproj.user/944892C3/sources/per/t/A12A982C @@ -0,0 +1,22 @@ +{ + "collab_server" : "", + "contents" : "", + "created" : 1571850698475.000, + "dirty" : false, + "encoding" : "UTF-8", + "folds" : "", + "hash" : "4141198788", + "id" : "A12A982C", + "lastKnownWriteTime" : 1571926602, + "last_content_update" : 1571926602900, + "path" : "C:/Users/Paklap.pk/Desktop/4th Webinar/Interactive_Dashboards/1. Preprocessing.R", + "project_path" : "1. Preprocessing.R", + "properties" : { + "cursorPosition" : "50,0", + "scrollLine" : "16" + }, + "relative_order" : 1, + "source_on_save" : false, + "source_window" : "", + "type" : "r_source" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/per/t/A12A982C-contents b/.Rproj.user/944892C3/sources/per/t/A12A982C-contents new file mode 100644 index 0000000..7139e93 --- /dev/null +++ b/.Rproj.user/944892C3/sources/per/t/A12A982C-contents @@ -0,0 +1,50 @@ + +#importing following packages +library(tidyverse) +library(lubridate) +library(dplyr) +library(ggplot2) +library(leaflet) + +#Packages can be installed using the code below: +#install.packages('leaflet') + +#importing data file 'crime.csv' +df <- read.csv(file = "crime.csv", header = TRUE, sep=",") +#view first few rows +head(df) + +#remove missing values +df <- na.omit(df) +#view number of rows and columns +dim(df) + + +#view data types +str(df) + +#Preprocessing +df$YEAR <- as.factor(df$YEAR) +df$HOUR <- as.factor(df$HOUR) +df$MONTH <- as.factor(df$MONTH) +df$OCCURRED_ON_DATE <- as.POSIXct(df$OCCURRED_ON_DATE, format = "%Y-%m-%d %H:%M:%OS") + + +str(df) + + + + + + +#Shiny App + +#importing shiny library +library(shiny) + + +ui <- basicPage("My first Shiny App") + +server <- function(input, output){} + +shinyApp(ui = ui, server = server) diff --git a/.Rproj.user/944892C3/sources/per/t/A8816B8B b/.Rproj.user/944892C3/sources/per/t/A8816B8B new file mode 100644 index 0000000..560f72e --- /dev/null +++ b/.Rproj.user/944892C3/sources/per/t/A8816B8B @@ -0,0 +1,22 @@ +{ + "collab_server" : "", + "contents" : "", + "created" : 1571852670998.000, + "dirty" : false, + "encoding" : "UTF-8", + "folds" : "", + "hash" : "324470682", + "id" : "A8816B8B", + "lastKnownWriteTime" : 1571920214, + "last_content_update" : 1571920214980, + "path" : "C:/Users/Paklap.pk/Desktop/4th Webinar/Interactive_Dashboards/4. UpdatedDashboard.R", + "project_path" : "4. UpdatedDashboard.R", + "properties" : { + "cursorPosition" : "64,0", + "scrollLine" : "31" + }, + "relative_order" : 4, + "source_on_save" : false, + "source_window" : "", + "type" : "r_source" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/per/t/A8816B8B-contents b/.Rproj.user/944892C3/sources/per/t/A8816B8B-contents new file mode 100644 index 0000000..656bc4d --- /dev/null +++ b/.Rproj.user/944892C3/sources/per/t/A8816B8B-contents @@ -0,0 +1,65 @@ + +body <- dashboardBody( + + fluidRow( + + box(title = "Crime Frequency", solidHeader = TRUE + ,collapsible = TRUE, plotOutput("barplot")), + + #Adding another box to our fluidRow + box(title = "Map View", solidHeader = TRUE + ,collapsible = TRUE, leafletOutput("mapview")) + + ) +) + +header <- dashboardHeader(title = "Boston Police") + +sidebar <- dashboardSidebar( + + radioButtons("year", "Select Year: ", + c("2015" = "2015", + "2016" = "2016", + "2017" = "2017", + "2018" = "2018", + "2019" = "2019")), + + #Adding a dropdown menu within the sidebar + selectInput("offense", + "Offense Group:", + c(unique(as.character(df$OFFENSE_CODE_GROUP[1:10])))) + +) + +ui <- dashboardPage(header, sidebar, body) + + +server <- function(input, output) { + + output$barplot <- renderPlot({ + + df_fil <- filter(df, YEAR == input$year) + df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) + ggplot(data = df_fil_grp, aes(x = df_fil_grp$HOUR)) + geom_bar() + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() + + }) + + #Defining our 'mapview' plot declared in the UI above + output$mapview <- renderLeaflet({ + + df_fil <- filter(df, YEAR == input$year) + df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) + dm <- data.frame(latitude = df_fil_grp$Lat, longitude = df_fil_grp$Long) + + leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% + addMarkers( + clusterOptions = markerClusterOptions() + ) %>% setView(-71.1, 42.32, zoom = 12) + + }) + +} + + +shinyApp(ui = ui, server = server) + diff --git a/.Rproj.user/944892C3/sources/per/t/B3E56EC9 b/.Rproj.user/944892C3/sources/per/t/B3E56EC9 new file mode 100644 index 0000000..fbcf620 --- /dev/null +++ b/.Rproj.user/944892C3/sources/per/t/B3E56EC9 @@ -0,0 +1,22 @@ +{ + "collab_server" : "", + "contents" : "", + "created" : 1571921116944.000, + "dirty" : false, + "encoding" : "UTF-8", + "folds" : "", + "hash" : "2538501940", + "id" : "B3E56EC9", + "lastKnownWriteTime" : 1571936330, + "last_content_update" : 1571936330757, + "path" : "C:/Users/Paklap.pk/Desktop/4th Webinar/Interactive_Dashboards/7. Advance.R", + "project_path" : "7. Advance.R", + "properties" : { + "cursorPosition" : "5,14", + "scrollLine" : "0" + }, + "relative_order" : 7, + "source_on_save" : false, + "source_window" : "", + "type" : "r_source" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/per/t/B3E56EC9-contents b/.Rproj.user/944892C3/sources/per/t/B3E56EC9-contents new file mode 100644 index 0000000..b25ea89 --- /dev/null +++ b/.Rproj.user/944892C3/sources/per/t/B3E56EC9-contents @@ -0,0 +1,147 @@ +library(tidyverse) +library(lubridate) +library(dplyr) +library(ggplot2) +library(leaflet) +library(shiny) +library(shinydashboard) + +df <- read.csv(file = "crime.csv", header = TRUE, sep=",") + +#remove missing values +df <- na.omit(df) + +#Preprocessing +df$YEAR <- as.factor(df$YEAR) +df$HOUR <- as.factor(df$HOUR) +df$MONTH <- as.factor(df$MONTH) +df$OCCURRED_ON_DATE <- as.POSIXct(df$OCCURRED_ON_DATE, format = "%Y-%m-%d %H:%M:%OS") + + + + + +row1 <- fluidRow( + + tabBox( + + title = "Crime Frequency", + id = "tabset1", height = "250px", + + tabPanel("Per Month", plotOutput("permonth")), + tabPanel("Per Weekday", plotOutput("perday")), + tabPanel("Per Hour", plotOutput("perhour")) + ) + + ,box(title = "Map View", solidHeader = TRUE + ,collapsible = TRUE, leafletOutput("mymap")) + +) + +#Creating another fluid row +row2 <- fluidRow( + box(title = "Stacked Plot", solidHeader = TRUE + ,collapsible = TRUE, plotOutput("stacked")) + + ,box(title = "Timeseries Plot", solidHeader = TRUE + ,collapsible = TRUE, plotOutput("timeseries")) +) + + +## Project Boston Crimes: UI - Header & Sidebars +header <- dashboardHeader(title = "Boston Crime Dataset") + +sidebar <- dashboardSidebar( + radioButtons("year", "Select Year: ", + c("2015" = "2015", + "2016" = "2016", + "2017" = "2017", + "2018" = "2018", + "2019" = "2019")), + + selectInput("offense", + "Offense Group:", + c(unique(as.character(df$OFFENSE_CODE_GROUP[1:10])))), + + + #Addition of a side bar menu to navigate to different tabs + sidebarMenu( + menuItem("Plots", tabName = "plots"), + menuItem("Table", tabName = "table") + ) + +) + +#Adding components to body: + + +body <- dashboardBody( + tabItems( + tabItem("plots", row1, row2), + tabItem("table", dataTableOutput('table')) +)) + + +#Adding all components to UI: +ui <- dashboardPage(header, sidebar, body) + + + +## Project Boston Crimes: Server +server <- function(input, output) { + + #creating a reactive object + filtered <- reactive({ + filter(filter(df, YEAR == input$year), OFFENSE_CODE_GROUP == input$offense) + }) + + #creating the plotOutput content + output$permonth <- renderPlot({ + ggplot(data = filtered(), aes(x = filtered()$MONTH)) + geom_bar(fill="steelblue") + xlab("Month") + ylab("Number of Crimes") + theme_minimal() + }) + + output$perday <- renderPlot({ + ggplot(data = filtered(), aes(x = filtered()$DAY_OF_WEEK)) + geom_bar(fill="red") + xlab("Day of Week") + ylab("Number of Crimes") + theme_minimal() + }) + + output$perhour <- renderPlot({ + ggplot(data = filtered(),aes(x = filtered()$HOUR)) + geom_bar(fill="green") + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() + }) + + #Defining the timeseries plot + output$timeseries <- renderPlot({ + + ggplot(data = filtered(), aes(x = filtered()$OCCURRED_ON_DATE))+ xlab("Date") + ylab("Number of Crimes") + geom_freqpoly(colour="purple") + }) + + #Defining the newly created stacked plot + output$stacked <- renderPlot({ + + filtered() %>% filter(DISTRICT %in% (filtered() %>% count(DISTRICT) %>% arrange(-n) %>% head(7) %>% pull(DISTRICT)), + OFFENSE_DESCRIPTION %in% (filtered() %>% count(OFFENSE_DESCRIPTION) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_DESCRIPTION))) %>% + ggplot(aes(DISTRICT, fill = OFFENSE_DESCRIPTION))+ + geom_bar(position = "fill") + }) + + output$mymap <- renderLeaflet({ + + dm <- data.frame(latitude = filtered()$Lat, longitude = filtered()$Long) + + leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% + addMarkers( + clusterOptions = markerClusterOptions() + ) %>% setView(-71.1, 42.32, zoom = 12) + + }) + + output$table <- renderDataTable( + filtered(), + options = list(scrollX = TRUE) + ) + +} + + + +## Project Boston Crimes: Building Our App +shinyApp(ui, server) diff --git a/.Rproj.user/944892C3/sources/per/t/D664F6C4 b/.Rproj.user/944892C3/sources/per/t/D664F6C4 new file mode 100644 index 0000000..a2e4fb7 --- /dev/null +++ b/.Rproj.user/944892C3/sources/per/t/D664F6C4 @@ -0,0 +1,22 @@ +{ + "collab_server" : "", + "contents" : "", + "created" : 1571850299833.000, + "dirty" : false, + "encoding" : "UTF-8", + "folds" : "", + "hash" : "1187509367", + "id" : "D664F6C4", + "lastKnownWriteTime" : 1571925648, + "last_content_update" : 1571925648650, + "path" : "C:/Users/Paklap.pk/Desktop/4th Webinar/Interactive_Dashboards/3. ShinyDashboard.R", + "project_path" : "3. ShinyDashboard.R", + "properties" : { + "cursorPosition" : "45,0", + "scrollLine" : "12" + }, + "relative_order" : 3, + "source_on_save" : false, + "source_window" : "", + "type" : "r_source" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/per/t/D664F6C4-contents b/.Rproj.user/944892C3/sources/per/t/D664F6C4-contents new file mode 100644 index 0000000..b19d47a --- /dev/null +++ b/.Rproj.user/944892C3/sources/per/t/D664F6C4-contents @@ -0,0 +1,46 @@ +#Building a simple Shiny Dashboard +library(shinydashboard) + +#Defining the body of the dashboard +body <- dashboardBody( + + #The body consists of a row-based layout with a single fluid row + fluidRow( + #Defining the output within a box + box(plotOutput("barplot")) + ) + +) + +#Defining the header object +header <- dashboardHeader(title = "Boston Police") + +#Defining the sidebard object +sidebar <- dashboardSidebar( + + radioButtons("year", "Select Year: ", + c("2015" = "2015", + "2016" = "2016", + "2017" = "2017", + "2018" = "2018", + "2019" = "2019")) + +) + +#Defining our ui object with a dashboardPage template +ui <- dashboardPage(header, sidebar, body) + + +server <- function(input, output) { + + output$barplot <- renderPlot({ + + df_fil <- filter(df, YEAR == input$year) + ggplot(data = df_fil, aes(x = df_fil$HOUR)) + geom_bar() + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() + + }) +} + + +shinyApp(ui, server) + diff --git a/.Rproj.user/944892C3/sources/prop/11F66727 b/.Rproj.user/944892C3/sources/prop/11F66727 new file mode 100644 index 0000000..bac64c9 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/11F66727 @@ -0,0 +1,5 @@ +{ + "cursorPosition" : "138,0", + "scrollLine" : "111", + "tempName" : "Untitled1" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/1A88722D b/.Rproj.user/944892C3/sources/prop/1A88722D new file mode 100644 index 0000000..d5b0a38 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/1A88722D @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "31,0", + "scrollLine" : "0" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/31EDA652 b/.Rproj.user/944892C3/sources/prop/31EDA652 new file mode 100644 index 0000000..b90bb36 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/31EDA652 @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "45,0", + "scrollLine" : "12" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/340440BD b/.Rproj.user/944892C3/sources/prop/340440BD new file mode 100644 index 0000000..9e9ce64 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/340440BD @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "47,0", + "scrollLine" : "0" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/3923804B b/.Rproj.user/944892C3/sources/prop/3923804B new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/3923804B @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/3C947E7E b/.Rproj.user/944892C3/sources/prop/3C947E7E new file mode 100644 index 0000000..7600ab7 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/3C947E7E @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "73,0", + "scrollLine" : "67" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/3D6D07B9 b/.Rproj.user/944892C3/sources/prop/3D6D07B9 new file mode 100644 index 0000000..e13ac07 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/3D6D07B9 @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "64,0", + "scrollLine" : "31" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/3E095C95 b/.Rproj.user/944892C3/sources/prop/3E095C95 new file mode 100644 index 0000000..cd83301 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/3E095C95 @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "32,0", + "scrollLine" : "9" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/43CCD005 b/.Rproj.user/944892C3/sources/prop/43CCD005 new file mode 100644 index 0000000..e5b5e61 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/43CCD005 @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "5,0", + "scrollLine" : "0" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/49194170 b/.Rproj.user/944892C3/sources/prop/49194170 new file mode 100644 index 0000000..c925790 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/49194170 @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "7,0", + "scrollLine" : "0" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/642D5398 b/.Rproj.user/944892C3/sources/prop/642D5398 new file mode 100644 index 0000000..3b5ab50 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/642D5398 @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "3,0", + "scrollLine" : "0" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/6A8E94CA b/.Rproj.user/944892C3/sources/prop/6A8E94CA new file mode 100644 index 0000000..306b2bb --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/6A8E94CA @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "0,0", + "scrollLine" : "0" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/725158E b/.Rproj.user/944892C3/sources/prop/725158E new file mode 100644 index 0000000..255e446 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/725158E @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "36,0", + "scrollLine" : "3" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/7502090B b/.Rproj.user/944892C3/sources/prop/7502090B new file mode 100644 index 0000000..61e7787 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/7502090B @@ -0,0 +1,5 @@ +{ + "cursorPosition" : "78,0", + "scrollLine" : "0", + "tempName" : "Untitled6" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/77A6324 b/.Rproj.user/944892C3/sources/prop/77A6324 new file mode 100644 index 0000000..6c61558 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/77A6324 @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "30,53", + "scrollLine" : "0" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/7E86B5E3 b/.Rproj.user/944892C3/sources/prop/7E86B5E3 new file mode 100644 index 0000000..daf6f60 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/7E86B5E3 @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "82,0", + "scrollLine" : "49" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/87094C22 b/.Rproj.user/944892C3/sources/prop/87094C22 new file mode 100644 index 0000000..4b77946 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/87094C22 @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "46,55", + "scrollLine" : "0" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/996C255D b/.Rproj.user/944892C3/sources/prop/996C255D new file mode 100644 index 0000000..e9fa990 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/996C255D @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "37,24", + "scrollLine" : "22" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/9978B5D1 b/.Rproj.user/944892C3/sources/prop/9978B5D1 new file mode 100644 index 0000000..25fa2d0 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/9978B5D1 @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "5,14", + "scrollLine" : "0" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/A45D2BB7 b/.Rproj.user/944892C3/sources/prop/A45D2BB7 new file mode 100644 index 0000000..306b2bb --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/A45D2BB7 @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "0,0", + "scrollLine" : "0" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/BE804CE4 b/.Rproj.user/944892C3/sources/prop/BE804CE4 new file mode 100644 index 0000000..5c51883 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/BE804CE4 @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "106,0", + "scrollLine" : "0" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/C1D6F94C b/.Rproj.user/944892C3/sources/prop/C1D6F94C new file mode 100644 index 0000000..a0b3f15 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/C1D6F94C @@ -0,0 +1,5 @@ +{ + "cursorPosition" : "115,0", + "scrollLine" : "0", + "tempName" : "Untitled7" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/C4DB5C5E b/.Rproj.user/944892C3/sources/prop/C4DB5C5E new file mode 100644 index 0000000..1712ede --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/C4DB5C5E @@ -0,0 +1,5 @@ +{ + "cursorPosition" : "25,0", + "scrollLine" : "19", + "tempName" : "Untitled4" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/C777DB4A b/.Rproj.user/944892C3/sources/prop/C777DB4A new file mode 100644 index 0000000..f1733e7 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/C777DB4A @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "50,0", + "scrollLine" : "16" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/DA893C6A b/.Rproj.user/944892C3/sources/prop/DA893C6A new file mode 100644 index 0000000..57bbf4c --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/DA893C6A @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "130,0", + "scrollLine" : "97" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/DABAA839 b/.Rproj.user/944892C3/sources/prop/DABAA839 new file mode 100644 index 0000000..dd1a7ce --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/DABAA839 @@ -0,0 +1,5 @@ +{ + "cursorPosition" : "33,0", + "scrollLine" : "0", + "tempName" : "Untitled1" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/EB7923CA b/.Rproj.user/944892C3/sources/prop/EB7923CA new file mode 100644 index 0000000..633148c --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/EB7923CA @@ -0,0 +1,4 @@ +{ + "cursorPosition" : "59,62", + "scrollLine" : "0" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/ED446F2C b/.Rproj.user/944892C3/sources/prop/ED446F2C new file mode 100644 index 0000000..887e568 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/ED446F2C @@ -0,0 +1,5 @@ +{ + "cursorPosition" : "2,11", + "scrollLine" : "0", + "tempName" : "Untitled5" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/FC40F374 b/.Rproj.user/944892C3/sources/prop/FC40F374 new file mode 100644 index 0000000..b56ef12 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/FC40F374 @@ -0,0 +1,5 @@ +{ + "cursorPosition" : "26,0", + "scrollLine" : "0", + "tempName" : "Untitled2" +} \ No newline at end of file diff --git a/.Rproj.user/944892C3/sources/prop/INDEX b/.Rproj.user/944892C3/sources/prop/INDEX new file mode 100644 index 0000000..9e29949 --- /dev/null +++ b/.Rproj.user/944892C3/sources/prop/INDEX @@ -0,0 +1,29 @@ +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FInteractive_Dashboards%2F1.%20Preprocessing.R="C777DB4A" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FInteractive_Dashboards%2F2.%20SimpleShinyApp.R="725158E" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FInteractive_Dashboards%2F3.%20ShinyDashboard.R="31EDA652" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FInteractive_Dashboards%2F4.%20UpdatedDashboard.R="3D6D07B9" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FInteractive_Dashboards%2F5.%20UpdatedDashboard_withTabs.R="7E86B5E3" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FInteractive_Dashboards%2F6.%20Final_Dashboard.R="DA893C6A" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FInteractive_Dashboards%2F7.%20Advance.R="9978B5D1" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FInteractive_Dashboards%2FAdvance.R="11F66727" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20Final%2F1.%20Preprocessing.R="996C255D" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20Final%2F2.%20SimpleShinyApp.R="642D5398" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20Final%2F3.%20ShinyDashboard.R="77A6324" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20Final%2F4.%20UpdatedDashboard.R="87094C22" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20Final%2F5.%20UpdatedDashboard_withTabs.R="EB7923CA" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20Final%2F6.%20Final_Dashboard.R="49194170" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20Final%2FFinal_Dashboard.R="C1D6F94C" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20Final%2FPreprocessing.R="DABAA839" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20Final%2FShinyDashboard.R="C4DB5C5E" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20Final%2FSimpleShinyApp.R="FC40F374" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20Final%2FUpdatedDashboard.R="ED446F2C" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20Final%2FUpdatedDashboard_withTabs.R="7502090B" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20work%2F1st.R="3E095C95" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20work%2F2nd.R="43CCD005" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20work%2F3rd.R="A45D2BB7" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20work%2F4th.R="3923804B" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20work%2F5th.R="6A8E94CA" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20work%2F6th.R="1A88722D" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20work%2F7th.R="340440BD" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2F4th%20Webinar%2FWebinar%20work%2Ffinal.R="BE804CE4" +C%3A%2FUsers%2FPaklap.pk%2FDesktop%2FData%20Science%20Dojo%2FBootcamp%2B%2B%2FRepo%2Frstudio_webinar%2Ffirst_published_r%2Fparta.R="3C947E7E" diff --git a/.Rproj.user/shared/notebooks/patch-chunk-names b/.Rproj.user/shared/notebooks/patch-chunk-names new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/.Rproj.user/shared/notebooks/patch-chunk-names diff --git a/.Rproj.user/shared/notebooks/paths b/.Rproj.user/shared/notebooks/paths new file mode 100644 index 0000000..2af64b8 --- /dev/null +++ b/.Rproj.user/shared/notebooks/paths @@ -0,0 +1,10 @@ +C:/Users/Paklap.pk/Desktop/4th Webinar/Interactive_Dashboards/Advance.R="A7A115B7" +C:/Users/Paklap.pk/Desktop/4th Webinar/Webinar work/1st.R="FA106C60" +C:/Users/Paklap.pk/Desktop/4th Webinar/Webinar work/2nd.R="E11FD119" +C:/Users/Paklap.pk/Desktop/4th Webinar/Webinar work/3rd.R="91C07CC0" +C:/Users/Paklap.pk/Desktop/4th Webinar/Webinar work/4th.R="61444EF2" +C:/Users/Paklap.pk/Desktop/4th Webinar/Webinar work/5th.R="AC2C9979" +C:/Users/Paklap.pk/Desktop/4th Webinar/Webinar work/6th.R="E8AAB7E9" +C:/Users/Paklap.pk/Desktop/4th Webinar/Webinar work/7th.R="50BA84C5" +C:/Users/Paklap.pk/Desktop/4th Webinar/Webinar work/final.R="1A14DF9F" +C:/Users/Paklap.pk/Desktop/Data Science Dojo/Bootcamp++/Repo/rstudio_webinar/first_published_r/parta.R="A6F9CBA1" diff --git a/1. Preprocessing.R b/1. Preprocessing.R index 901fbf2..7139e93 100644 --- a/1. Preprocessing.R +++ b/1. Preprocessing.R @@ -14,9 +14,12 @@ df <- read.csv(file = "crime.csv", header = TRUE, sep=",") #view first few rows head(df) +#remove missing values +df <- na.omit(df) #view number of rows and columns dim(df) + #view data types str(df) @@ -26,6 +29,7 @@ df$HOUR <- as.factor(df$HOUR) df$MONTH <- as.factor(df$MONTH) df$OCCURRED_ON_DATE <- as.POSIXct(df$OCCURRED_ON_DATE, format = "%Y-%m-%d %H:%M:%OS") + str(df) @@ -44,6 +48,3 @@ ui <- basicPage("My first Shiny App") server <- function(input, output){} shinyApp(ui = ui, server = server) - - - diff --git a/2. SimpleShinyApp.R b/2. SimpleShinyApp.R index 43b1e74..e7e247f 100644 --- a/2. SimpleShinyApp.R +++ b/2. SimpleShinyApp.R @@ -12,7 +12,8 @@ ui <- fluidPage( "2018" = "2018", "2019" = "2019")), - #setting an output in form of plot + + #setting an output in form of plot plotOutput("barplot") ) @@ -25,7 +26,6 @@ server <- function(input, output){ #filtering data with respect to input from radio buttons using 'year' ID df_fil <- filter(df, YEAR == input$year) - #defining the barplot using ggplot2 ggplot(data = df_fil, aes(x = df_fil$HOUR)) + geom_bar() + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() @@ -34,3 +34,4 @@ server <- function(input, output){ shinyApp(ui = ui, server = server) + diff --git a/3. ShinyDashboard.R b/3. ShinyDashboard.R index 18b688f..b19d47a 100644 --- a/3. ShinyDashboard.R +++ b/3. ShinyDashboard.R @@ -1,4 +1,3 @@ - #Building a simple Shiny Dashboard library(shinydashboard) @@ -14,7 +13,7 @@ body <- dashboardBody( ) #Defining the header object -header <- dashboardHeader(title = "Boston Crimes Dataset") +header <- dashboardHeader(title = "Boston Police") #Defining the sidebard object sidebar <- dashboardSidebar( diff --git a/4. UpdatedDashboard.R b/4. UpdatedDashboard.R index 7c4d29a..656bc4d 100644 --- a/4. UpdatedDashboard.R +++ b/4. UpdatedDashboard.R @@ -13,7 +13,7 @@ body <- dashboardBody( ) ) -header <- dashboardHeader(title = "Boston Crimes Dataset") +header <- dashboardHeader(title = "Boston Police") sidebar <- dashboardSidebar( @@ -26,9 +26,8 @@ sidebar <- dashboardSidebar( #Adding a dropdown menu within the sidebar selectInput("offense", - "Offense Description:", - c("All", - unique(as.character(df$OFFENSE_DESCRIPTION[1:10])))) + "Offense Group:", + c(unique(as.character(df$OFFENSE_CODE_GROUP[1:10])))) ) @@ -40,15 +39,17 @@ server <- function(input, output) { output$barplot <- renderPlot({ df_fil <- filter(df, YEAR == input$year) - ggplot(data = df_fil, aes(x = df_fil$HOUR)) + geom_bar() + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() + df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) + ggplot(data = df_fil_grp, aes(x = df_fil_grp$HOUR)) + geom_bar() + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() }) #Defining our 'mapview' plot declared in the UI above output$mapview <- renderLeaflet({ - df_fil_map <- filter(df, OFFENSE_DESCRIPTION == input$offense) - dm <- data.frame(latitude = df_fil_map$Lat[1:500], longitude = df_fil_map$Long[1:500]) + df_fil <- filter(df, YEAR == input$year) + df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) + dm <- data.frame(latitude = df_fil_grp$Lat, longitude = df_fil_grp$Long) leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% addMarkers( diff --git a/5. UpdatedDashboard_withTabs.R b/5. UpdatedDashboard_withTabs.R index 3ed20b5..a564bcd 100644 --- a/5. UpdatedDashboard_withTabs.R +++ b/5. UpdatedDashboard_withTabs.R @@ -30,9 +30,8 @@ sidebar <- dashboardSidebar( "2019" = "2019")), selectInput("offense", - "Offense Description:", - c("All", - unique(as.character(df$OFFENSE_DESCRIPTION[1:10])))) + "Offense Group:", + c(unique(as.character(df$OFFENSE_CODE_GROUP[1:10])))) ) @@ -46,25 +45,29 @@ server <- function(input, output) { #creating the plotOutput content output$permonth <- renderPlot({ - df1 <- filter(df, YEAR == input$year) - ggplot(data = df1,aes(x=df1$MONTH)) + geom_bar(fill="steelblue") + xlab("Month") + ylab("Number of Crimes") + theme_minimal() + df_fil <- filter(df, YEAR == input$year) + df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) + ggplot(data = df_fil_grp,aes(x = df_fil_grp$MONTH)) + geom_bar(fill="steelblue") + xlab("Month") + ylab("Number of Crimes") + theme_minimal() }) output$perday <- renderPlot({ - df1 <- filter(df, YEAR == input$year) - ggplot(data = df1,aes(x=df1$DAY_OF_WEEK)) + geom_bar(fill="red") + xlab("Day of Week") + ylab("Number of Crimes") + theme_minimal() + df_fil <- filter(df, YEAR == input$year) + df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) + ggplot(data = df_fil_grp,aes(x = df_fil_grp$DAY_OF_WEEK)) + geom_bar(fill="red") + xlab("Day of Week") + ylab("Number of Crimes") + theme_minimal() }) output$perhour <- renderPlot({ - df1 <- filter(df, YEAR == input$year) - ggplot(data = df1,aes(x=df1$HOUR)) + geom_bar(fill="purple") + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() + df_fil <- filter(df, YEAR == input$year) + df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) + ggplot(data = df_fil_grp,aes(x = df_fil_grp$HOUR)) + geom_bar(fill="purple") + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() }) output$mymap <- renderLeaflet({ - df_fil_off <- filter(df, OFFENSE_DESCRIPTION == input$offense) - dm <- data.frame(latitude = df_fil_off$Lat[1:500], longitude = df_fil_off$Long[1:500]) + df_fil <- filter(df, YEAR == input$year) + df_fil_grp <- filter(df_fil, OFFENSE_CODE_GROUP == input$offense) + dm <- data.frame(latitude = df_fil_grp$Lat, longitude = df_fil_grp$Long) leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% addMarkers( @@ -75,6 +78,5 @@ server <- function(input, output) { } - ## Project Boston Crimes: Building Our App shinyApp(ui, server) diff --git a/6. Final_Dashboard.R b/6. Final_Dashboard.R index bbd09b1..c8db850 100644 --- a/6. Final_Dashboard.R +++ b/6. Final_Dashboard.R @@ -8,6 +8,9 @@ library(shinydashboard) df <- read.csv(file = "crime.csv", header = TRUE, sep=",") +#remove missing values +df <- na.omit(df) + #Preprocessing df$YEAR <- as.factor(df$YEAR) df$HOUR <- as.factor(df$HOUR) @@ -19,15 +22,20 @@ df$OCCURRED_ON_DATE <- as.POSIXct(df$OCCURRED_ON_DATE, format = "%Y-%m-%d %H:%M: row1 <- fluidRow( + tabBox( + title = "Crime Frequency", id = "tabset1", height = "250px", + tabPanel("Per Month", plotOutput("permonth")), tabPanel("Per Weekday", plotOutput("perday")), tabPanel("Per Hour", plotOutput("perhour")) ) + ,box(title = "Map View", solidHeader = TRUE ,collapsible = TRUE, leafletOutput("mymap")) + ) #Creating another fluid row @@ -57,8 +65,8 @@ sidebar <- dashboardSidebar( "2019" = "2019")), selectInput("offense", - "Offense Description:", - c(unique(as.character(df$OFFENSE_DESCRIPTION[1:10])))) + "Offense Group:", + c(unique(as.character(df$OFFENSE_CODE_GROUP[1:10])))) ) @@ -69,44 +77,43 @@ ui <- dashboardPage(header, sidebar, body) ## Project Boston Crimes: Server server <- function(input, output) { + + #creating a reactive object + filtered <- reactive({ + filter(filter(df, YEAR == input$year), OFFENSE_CODE_GROUP == input$offense) + }) #creating the plotOutput content output$permonth <- renderPlot({ - df1 <- filter(df, YEAR == input$year) - ggplot(data = df1,aes(x=df1$MONTH)) + geom_bar(fill="steelblue") + xlab("Month") + ylab("Number of Crimes") + theme_minimal() + ggplot(data = filtered(), aes(x = filtered()$MONTH)) + geom_bar(fill="steelblue") + xlab("Month") + ylab("Number of Crimes") + theme_minimal() }) - + output$perday <- renderPlot({ - df1 <- filter(df, YEAR == input$year) - ggplot(data = df1,aes(x=df1$DAY_OF_WEEK)) + geom_bar(fill="red") + xlab("Day of Week") + ylab("Number of Crimes") + theme_minimal() + ggplot(data = filtered(), aes(x = filtered()$DAY_OF_WEEK)) + geom_bar(fill="red") + xlab("Day of Week") + ylab("Number of Crimes") + theme_minimal() }) - + output$perhour <- renderPlot({ - df1 <- filter(df, YEAR == input$year) - ggplot(data = df1,aes(x=df1$HOUR)) + geom_bar(fill="purple") + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() + ggplot(data = filtered(),aes(x = filtered()$HOUR)) + geom_bar(fill="green") + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() }) - + #Defining the timeseries plot output$timeseries <- renderPlot({ - df_fil_off <- filter(df, OFFENSE_DESCRIPTION == input$offense) - ggplot(data = df_fil_off, aes(x = df_fil_off$OCCURRED_ON_DATE))+ xlab("Date") + ylab("Number of Crimes") + geom_freqpoly(colour="green") + ggplot(data = filtered(), aes(x = filtered()$OCCURRED_ON_DATE))+ xlab("Date") + ylab("Number of Crimes") + geom_freqpoly(colour="purple") }) #Defining the newly created stacked plot output$stacked <- renderPlot({ - df %>% filter(STREET %in% (df %>% count(STREET) %>% arrange(-n) %>% head(10) %>% pull(STREET)), - OFFENSE_DESCRIPTION %in% (df %>% count(OFFENSE_DESCRIPTION) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_DESCRIPTION))) %>% - ggplot(aes(STREET, fill = OFFENSE_DESCRIPTION))+ - geom_bar(position = "fill")+ - scale_fill_ordinal()+ - coord_flip() + + filtered() %>% filter(DISTRICT %in% (filtered() %>% count(DISTRICT) %>% arrange(-n) %>% head(7) %>% pull(DISTRICT)), + OFFENSE_DESCRIPTION %in% (filtered() %>% count(OFFENSE_DESCRIPTION) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_DESCRIPTION))) %>% + ggplot(aes(DISTRICT, fill = OFFENSE_DESCRIPTION))+ + geom_bar(position = "fill") }) output$mymap <- renderLeaflet({ - df_fil_off <- filter(df, OFFENSE_DESCRIPTION == input$offense) - dm <- data.frame(latitude = df_fil_off$Lat[1:500], longitude = df_fil_off$Long[1:500]) + dm <- data.frame(latitude = filtered()$Lat, longitude = filtered()$Long) leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% addMarkers( diff --git a/7. Advance.R b/7. Advance.R new file mode 100644 index 0000000..b25ea89 --- /dev/null +++ b/7. Advance.R @@ -0,0 +1,147 @@ +library(tidyverse) +library(lubridate) +library(dplyr) +library(ggplot2) +library(leaflet) +library(shiny) +library(shinydashboard) + +df <- read.csv(file = "crime.csv", header = TRUE, sep=",") + +#remove missing values +df <- na.omit(df) + +#Preprocessing +df$YEAR <- as.factor(df$YEAR) +df$HOUR <- as.factor(df$HOUR) +df$MONTH <- as.factor(df$MONTH) +df$OCCURRED_ON_DATE <- as.POSIXct(df$OCCURRED_ON_DATE, format = "%Y-%m-%d %H:%M:%OS") + + + + + +row1 <- fluidRow( + + tabBox( + + title = "Crime Frequency", + id = "tabset1", height = "250px", + + tabPanel("Per Month", plotOutput("permonth")), + tabPanel("Per Weekday", plotOutput("perday")), + tabPanel("Per Hour", plotOutput("perhour")) + ) + + ,box(title = "Map View", solidHeader = TRUE + ,collapsible = TRUE, leafletOutput("mymap")) + +) + +#Creating another fluid row +row2 <- fluidRow( + box(title = "Stacked Plot", solidHeader = TRUE + ,collapsible = TRUE, plotOutput("stacked")) + + ,box(title = "Timeseries Plot", solidHeader = TRUE + ,collapsible = TRUE, plotOutput("timeseries")) +) + + +## Project Boston Crimes: UI - Header & Sidebars +header <- dashboardHeader(title = "Boston Crime Dataset") + +sidebar <- dashboardSidebar( + radioButtons("year", "Select Year: ", + c("2015" = "2015", + "2016" = "2016", + "2017" = "2017", + "2018" = "2018", + "2019" = "2019")), + + selectInput("offense", + "Offense Group:", + c(unique(as.character(df$OFFENSE_CODE_GROUP[1:10])))), + + + #Addition of a side bar menu to navigate to different tabs + sidebarMenu( + menuItem("Plots", tabName = "plots"), + menuItem("Table", tabName = "table") + ) + +) + +#Adding components to body: + + +body <- dashboardBody( + tabItems( + tabItem("plots", row1, row2), + tabItem("table", dataTableOutput('table')) +)) + + +#Adding all components to UI: +ui <- dashboardPage(header, sidebar, body) + + + +## Project Boston Crimes: Server +server <- function(input, output) { + + #creating a reactive object + filtered <- reactive({ + filter(filter(df, YEAR == input$year), OFFENSE_CODE_GROUP == input$offense) + }) + + #creating the plotOutput content + output$permonth <- renderPlot({ + ggplot(data = filtered(), aes(x = filtered()$MONTH)) + geom_bar(fill="steelblue") + xlab("Month") + ylab("Number of Crimes") + theme_minimal() + }) + + output$perday <- renderPlot({ + ggplot(data = filtered(), aes(x = filtered()$DAY_OF_WEEK)) + geom_bar(fill="red") + xlab("Day of Week") + ylab("Number of Crimes") + theme_minimal() + }) + + output$perhour <- renderPlot({ + ggplot(data = filtered(),aes(x = filtered()$HOUR)) + geom_bar(fill="green") + xlab("Hour") + ylab("Number of Crimes") + theme_minimal() + }) + + #Defining the timeseries plot + output$timeseries <- renderPlot({ + + ggplot(data = filtered(), aes(x = filtered()$OCCURRED_ON_DATE))+ xlab("Date") + ylab("Number of Crimes") + geom_freqpoly(colour="purple") + }) + + #Defining the newly created stacked plot + output$stacked <- renderPlot({ + + filtered() %>% filter(DISTRICT %in% (filtered() %>% count(DISTRICT) %>% arrange(-n) %>% head(7) %>% pull(DISTRICT)), + OFFENSE_DESCRIPTION %in% (filtered() %>% count(OFFENSE_DESCRIPTION) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_DESCRIPTION))) %>% + ggplot(aes(DISTRICT, fill = OFFENSE_DESCRIPTION))+ + geom_bar(position = "fill") + }) + + output$mymap <- renderLeaflet({ + + dm <- data.frame(latitude = filtered()$Lat, longitude = filtered()$Long) + + leaflet(dm) %>% addProviderTiles("Stamen.TonerLite") %>% + addMarkers( + clusterOptions = markerClusterOptions() + ) %>% setView(-71.1, 42.32, zoom = 12) + + }) + + output$table <- renderDataTable( + filtered(), + options = list(scrollX = TRUE) + ) + +} + + + +## Project Boston Crimes: Building Our App +shinyApp(ui, server) -- libgit2 0.26.0