library(reportsWS)
library(forecast)
library(dygraphs)
library(shiny)

# Select name and gender
textInput(inputId = "name", label = "Type a name", value = "Garrett")
radioButtons(inputId = "sex", label = "Choose gender",
             choices = c("M", "F"), inline = TRUE)
names <- reactive(get_babyname(input$name, input$sex))

# Create time series and forecast
nbirths <- reactive(ts(names()$n, start = 1880))

pred <- reactive({
  mod <- auto.arima(nbirths())
  forecast(mod, h = 12) # 12 for 2025
})

Since 1880, r renderText(sum(nbirths(), na.rm = TRUE)) children have been named r renderText(input$name). The graph below breaks this number down by year showing the number of children named r renderText(input$name) as a time series.

renderDygraph({
  title <- paste0("Number of children named ", input$name)
  all <- bind_as_xts(nbirths(), pred()) 

  dygraph(all, main = title) %>%
    dySeries("x", label = "n children") %>% 
    dySeries(c("lower", "fitted", "upper"), label = "Predicted") %>% 
    dyRangeSelector()
})

We modeled this time series with an r renderText(trim_whitespace(pred()$method)) model to predict the number of children that will be given the name r renderText(input$name) in 2025.

renderTable({
  data.frame(
    method = trim_whitespace(pred()$method), 
    predicted_2025 = round(xts::last(pred()$mean)))
})


rstudio/reportsWS documentation built on May 28, 2019, 5:42 a.m.