Dipesh Shrestha
30th May 2016
Github:
The application uses R code to calculate the future US population between the years 2014 and 2040 using historical population data from the past 34 years (i.e. 1980 to 2013) and linear regression based on those past data points.
It basically does the following:
The getPop() function in server.R extracts and cleans the historical data:
library(XML)
getPop <- function() {
#Get the population data from the Internet and parse it out into a data.frame called Pop, then format it's columns
theurl <- "http://www.usgovernmentspending.com/download_multi_year_1980_2013USb_14c2li101mcn_20s"
tables <- readHTMLTable(theurl)
n.rows <- unlist(lapply(tables, function(t) dim(t)[1]))
tables[[which.max(n.rows)]]
x <- tables$"Government Spending ChartFiscal Years 1980 to 2013"
Pop <- head(x[,c(1,3)], 34, stringsAsFactors = FALSE)
colnames(Pop) <- c("Year","Population (in millions)")
Pop$Year <- round(as.numeric(levels(Pop$Year))[Pop$Year])
Pop$"Population (in millions)" <- as.numeric(levels(Pop$"Population (in millions)"))[Pop$"Population (in millions)"]
return (Pop)
}
#Get cached data from the Internet (to save time from reloading data everytime server.R code is called)
Pop <<- getPop()
This tiny shiny app is just a part of peer assignment on a Data Science Coursera Course - Developing Data Products. The objective of this little application is to predict the population of United States of America based on the given data set.
My app is available at: https://dishrestha.shinyapps.io/ShinyAppps/