Last active
October 22, 2017 21:58
-
-
Save jmatamatics/b8dad269be90038d6ff21b17e07e2fdd to your computer and use it in GitHub Desktop.
Code for leading causes of death in NYC from 2007-2014
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(shiny) | |
| library(ggplot2) | |
| library(dplyr) | |
| load("death.Rdata") | |
| #death <- read_csv(leadingdeath/death.csv) | |
| shinyServer(function(input, output) { | |
| output$header <- renderText({ | |
| paste("You have selected", input$ethnicity, input$sex) | |
| }) | |
| output$bar <- renderPlot({ | |
| ifelse(input$ethnicity == "All 4 Races", | |
| filtered.death <- death %>% filter(Year == input$range, Sex == input$sex), | |
| filtered.death <- death %>% filter(Year == input$range, Race.Ethnicity == input$ethnicity, Sex == input$sex)) | |
| g <- ggplot(data= filtered.death,aes(x=Leading.Cause,Deaths)) | |
| g + geom_bar(aes(fill=Leading.Cause), stat = "identity") + | |
| xlab(input$range)+ylab("Deaths") + theme_classic() + theme(axis.text.x=element_blank()) | |
| }) | |
| output$head <- renderText({ | |
| paste("You have selected", input$eth, input$s) | |
| }) | |
| output$b<- renderPlot({ | |
| ifelse(input$eth == "All 4 Races", | |
| filtered.death <- death %>% filter(Year == input$r, Sex == input$s), | |
| filtered.death <- death %>% filter(Year == input$r, Race.Ethnicity == input$eth, Sex == input$s)) | |
| g <- ggplot(data= filtered.death,aes(x=Leading.Cause,Deaths)) | |
| g + geom_bar(aes(fill=Leading.Cause), stat = "identity") + | |
| xlab(input$range)+ylab("Deaths") + theme_classic() + theme(axis.text.x=element_blank()) | |
| }) | |
| }) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(shiny) | |
| # Define UI for application that draws bar graph | |
| shinyUI(fluidPage( | |
| # Application title | |
| titlePanel(" Leading Causes of Deaths In NYC(2007-2014)"), | |
| sidebarLayout( | |
| sidebarPanel( | |
| selectInput("ethnicity", # choose the race | |
| label = "Choose a ethnicity to display", | |
| choices = c("White", "Black", "Hispanic", "Asian", "All 4 Races"), | |
| selected = "Hispanic"), | |
| selectInput("sex", # choose the sex | |
| label = "Choose a sex to display", | |
| choices = c("Male","Female"), | |
| selected = "Male"), | |
| sliderInput("range", label = "Year", | |
| min = 2007, max = 2014, | |
| value = 2007, step = 1, | |
| pre = "", sep = "", | |
| animate = TRUE) | |
| ), | |
| # Show a bar graph | |
| mainPanel( | |
| textOutput("header"), | |
| tableOutput("test"), | |
| plotOutput("bar", height = "300px") | |
| ) | |
| ), | |
| sidebarLayout( | |
| sidebarPanel( | |
| selectInput("eth", # choose the race | |
| label = "Choose a ethinicity to display", | |
| choices = c("White", "Black", "Hispanic", "Asian", "All 4 Races"), | |
| selected = "Black"), | |
| selectInput("s", # choose the sex | |
| label = "Choose a sex to display", | |
| choices = c("Male","Female"), | |
| selected = "Male"), | |
| sliderInput("r", label = "Year", | |
| min = 2007, max = 2014, | |
| value = 2007, step = 1, | |
| pre = "", sep = "", | |
| animate = TRUE) | |
| ), | |
| # Show a bar graph | |
| mainPanel( | |
| textOutput("head"), | |
| tableOutput("t"), | |
| plotOutput("b", height = "300px") | |
| ) | |
| ) | |
| ) | |
| ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment