3. ShinyDashboard.R 1009 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#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
Sanjay Pant committed
16
header <- dashboardHeader(title = "Boston Police")
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

#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)