Skip to content

Commit

Permalink
v4
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisliub committed Apr 22, 2015
1 parent 7850090 commit b47bc6b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions shiny_propotype/v4/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,31 @@ getTimingPlot4 <- function(ds) {
ylab('Fatalities')
g
}

getSummaryPlot1 <- function(ds,slider_min_max) {
min <- slider_min_max[1]
max <- slider_min_max[2]
a <- ds$vehicles
df <- a %>% group_by(MOD_YEAR) %>% summarize(fatalities=sum(DEATHS))
df <- df[df$MOD_YEAR<2015 & df$MOD_YEAR<max_year & df$MOD_YEAR>min_year,]
g <- ggplot(df, aes(x=MOD_YEAR, y=fatalities)) +
geom_bar(stat='identity') +
theme_bw() +
theme(legend.key = element_blank()) +
theme(legend.title = element_blank()) +
xlab('') +
ylab('Fatalities')
g
}


shinyServer(function(input, output) {
ds <- loadFatalityDataset(2013, '../../')
output$timingPlot1 <- renderPlot({getTimingPlot1(ds)})
output$timingPlot2 <- renderPlot({getTimingPlot2(ds)})
output$timingPlot3 <- renderPlot({getTimingPlot3(ds)})
output$timingPlot4 <- renderPlot({getTimingPlot4(ds)})
output$summaryPlot1 <- renderPlot({getSummaryPlot1(ds,input$vehicle_year_slider)})
})


10 changes: 10 additions & 0 deletions shiny_propotype/v4/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ tabItems(
column(width=12,
h2("General summary"),
p("by state"),
h3('Number of fatalities per vehicle year'),
fluidRow(
column(1,

# Copy the line below to make a slider bar
sliderInput("vehicle_year_slider", label = h3("Slider"), min = 1917,
max = 2014, value = c(1917,2014))

),
column(10,plotOutput("summaryPlot1"))),
p("by number of fatalities"),
p("by type of vehicle"),
p("Rollover fatalities"),
Expand Down

0 comments on commit b47bc6b

Please sign in to comment.