Created
February 8, 2013 03:01
-
-
Save atbradley/4736289 to your computer and use it in GitHub Desktop.
A shiny app using Social Security baby names data aggregated by Hadley Wickham (https://github.com/hadley/data-baby-names).
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) | |
| #This is at http://raw.github.com/hadley/data-baby-names/master/baby-names.csv | |
| names <- read.csv('~/R/baby-names.csv') | |
| # Define server logic required to plot various variables against mpg | |
| shinyServer(function(input, output) { | |
| # Return the formula text for printing as a caption | |
| output$caption <- reactiveText(function() { | |
| "Plot" | |
| }) | |
| output$subCaption <- reactiveText(function() { | |
| "Plot" | |
| }) | |
| output$plot <- reactivePlot(function() { | |
| nms <- names[names$year==input$baseYear,] | |
| nms <- nms[nms$sex==input$sex,] | |
| nms <- nms$name[order(nms$percent, decreasing=T)] | |
| nms <- nms[1:input$nameCount] | |
| wrk <- names[names$name %in% nms,] | |
| wrk <- wrk[wrk$sex==input$sex,] | |
| wrk <- wrk[wrk$year %in% | |
| seq(from=input$yearRange[[1]], | |
| to=input$yearRange[[2]]),] | |
| plt <- ggplot(wrk) + | |
| geom_line(aes(year, percent, colour=name)) | |
| print(plt) | |
| }) | |
| }) |
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 miles per gallon application | |
| shinyUI(pageWithSidebar( | |
| # Application title | |
| headerPanel("Baby Names"), | |
| sidebarPanel( | |
| selectInput('sex', 'Sex:', | |
| list('Male' = 'boy', | |
| 'Female' = 'girl')), | |
| sliderInput('nameCount', 'Number of popular names to plot:', | |
| min=1, max=10, value=5), | |
| sliderInput('baseYear', 'Year to choose popular names from:', | |
| min=1880, max=2008, value=1880), | |
| sliderInput("yearRange", "Years to plot:", | |
| min = 1880, max = 2008, value = c(1880,2008)) | |
| ), | |
| mainPanel( | |
| h3(textOutput("caption")), | |
| h4(textOutput("subCaption")), | |
| plotOutput("plot") | |
| ) | |
| )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment