Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cc98139
Showing
13 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Package: blsBandit | ||
Title: Data Viewer for Bureau of Labor Statistics Data | ||
Version: 0.1 | ||
Authors@R: | ||
person(given = "Jeremy", | ||
family = "Fitzpatrick", | ||
role = c("aut", "cre"), | ||
email = "jmfitzpa@gmail.com") | ||
Description: Allows users to easily visualize data from the BLS (United States of America Bureau of Labor Statistics) <https://www.bls.gov>. Currently unemployment data series U1-U6 are available. Not affiliated with the Bureau of Labor Statistics or United States Government. | ||
License: MIT + file LICENSE | ||
Imports: DBI (>= 1.1.3), jsonlite (>= 1.8.4), plotly (>= 4.10.2), | ||
RSQLite (>= 2.2.16), shiny (>= 1.7.1), zoo (>= 1.8-12) | ||
Encoding: UTF-8 | ||
RoxygenNote: 7.2.0 | ||
NeedsCompilation: no | ||
Packaged: 2023-08-22 21:58:33 UTC; Taco | ||
Author: Jeremy Fitzpatrick [aut, cre] | ||
Maintainer: Jeremy Fitzpatrick <jmfitzpa@gmail.com> | ||
Repository: CRAN | ||
Date/Publication: 2023-08-23 19:30:02 UTC |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
YEAR: 2023 | ||
COPYRIGHT HOLDER: Jeremy Fitzpatrick |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
11357e9ba71eea8b36b253ecd1a92e04 *DESCRIPTION | ||
0bc764a9dde70ea0c50fb69fd411026a *LICENSE | ||
ff224a6198b9b871e261cc790346537b *NAMESPACE | ||
4d74bb087ce7f72cddeed7493e9ede3d *R/blsSelect.R | ||
13e7746a5600387b4015255971a119c1 *R/blsViewer.R | ||
56167f5afa5c268c5489fdc479381a6f *R/blsViewerServer.R | ||
6d9dfa2f47ba8d8ff6347e29cec716c3 *R/blsViewerUI.R | ||
6e4614bd6dc3df08f2dcfee200e7b4c1 *R/imports.R | ||
66db8598112e29594c5ef729b3a29bcb *R/unemploymentPlot.R | ||
56dd1f49016edd3c5c93a15c92023b46 *README.md | ||
a6301c9442c5cef9e1eac9f7428a046d *inst/extdata/blsData.sqlite | ||
2279f443a38070d6fd36a0d29db13363 *man/blsViewer.Rd |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(blsViewer) | ||
import(DBI) | ||
import(RSQLite) | ||
import(plotly) | ||
import(shiny) | ||
importFrom(jsonlite,fromJSON) | ||
importFrom(utils,head) | ||
importFrom(utils,tail) | ||
importFrom(zoo,as.yearmon) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#' Select BLS Data | ||
#' | ||
#' This function should not be run by the user. | ||
#' @param query A valid SQL SELECT query | ||
#' @noRd | ||
blsSelect <- function(query) { | ||
dbLocation <- system.file("extdata", "blsData.sqlite", package = "blsBandit") | ||
con <- dbConnect(RSQLite::SQLite(), dbname = dbLocation) | ||
queryResult <- dbGetQuery(con, query) | ||
dbDisconnect(con) | ||
return(queryResult) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#' Run the BLS Viewer | ||
#' | ||
#' This function runs the BLS (US Bureau of Labor Statistics) data viewer. | ||
#' Currently this viewer allows the user to select and view unemployment data. | ||
#' The data is static as the package blsAPI is no longer available on CRAN. | ||
#' To install the latest version of blsBandit and the blsAPI with update data | ||
#' functionality install them from github. | ||
#' blsAPI<https://github.com/mikeasilva/blsAPI> | ||
#' blsBandit<https://github.com/Jeremy-Fitzpatrick/blsBandit> | ||
#' The blsBandit package is not affiliated with the Bureau of Labor Statistics | ||
#' or US Government. | ||
#' @keywords BLS Unemployment | ||
#' @export | ||
#' @examples | ||
#' # Run the BLS data viewer. | ||
#' if(interactive()){blsViewer()} | ||
#' @return No return value. The user can save charts from within the interface. | ||
blsViewer <- function() { | ||
shinyApp(ui = blsViewUI, server = blsViewerServer) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#' Shiny Server Logic for blsViewer | ||
#' | ||
#' This function should not be run by the user. | ||
#' @param input,output,session Internal shiny parameters. | ||
#' @noRd | ||
blsViewerServer <- function(input, output, session) { | ||
## Update selections based on available unemployment series. | ||
updateSelectizeInput("unemploymentSeries", | ||
session = session, | ||
choices = blsSelect("SELECT uiName FROM blsSeriesNames;")$uiName, | ||
selected = blsSelect("SELECT uiName FROM blsSeriesNames;")$uiName[3] | ||
) | ||
|
||
## Update years selections, based on unemployment series selection. | ||
observeEvent(input$unemploymentSeries, | ||
{ | ||
years <- blsSelect(paste0( | ||
"SELECT DISTINCT year FROM blsDataSeries ", | ||
"INNER JOIN blsSeriesNames ON ", | ||
"blsSeriesNames.seriesID = blsDataSeries.fk_seriesID ", | ||
"WHERE uiName IN ('", | ||
paste(input$unemploymentSeries, collapse = "','"), | ||
"');" | ||
))$year | ||
years <- sort(years) | ||
updateSelectizeInput("selectStartYear", | ||
session = session, choices = head(years, -1), | ||
selected = min(years) | ||
) | ||
updateSelectizeInput("selectEndYear", | ||
session = session, choices = tail(years, -1), | ||
selected = max(years) | ||
) | ||
}, | ||
ignoreInit = TRUE, | ||
ignoreNULL = TRUE | ||
) | ||
|
||
## Ensure that the start year is acceptable. Create plot based on years selected. | ||
observeEvent(input$selectStartYear, | ||
{ | ||
if (input$selectStartYear > input$selectEndYear) { | ||
updateSelectizeInput("selectEndYear", | ||
session = session, selected = as.character(as.numeric(input$selectStartYear) + 1) | ||
) | ||
} else { | ||
output$unemploymentPlot <- renderPlotly({ | ||
unemploymentPlot( | ||
input$unemploymentSeries, input$selectStartYear, input$selectEndYear | ||
) | ||
}) | ||
} | ||
}, | ||
ignoreNULL = TRUE, | ||
ignoreInit = TRUE | ||
) | ||
|
||
## Ensure that the end year is acceptable. Create plot based on years selected. | ||
observeEvent(input$selectEndYear, | ||
{ | ||
if (input$selectStartYear > input$selectEndYear) { | ||
updateSelectizeInput("selectStartYear", | ||
session = session, selected = as.character(as.numeric(input$selectEndYear) - 1) | ||
) | ||
} else { | ||
output$unemploymentPlot <- renderPlotly({ | ||
unemploymentPlot( | ||
input$unemploymentSeries, input$selectStartYear, input$selectEndYear | ||
) | ||
}) | ||
} | ||
}, | ||
ignoreNULL = TRUE, | ||
ignoreInit = TRUE | ||
) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#' The User-Interface for the blsViewer | ||
#' | ||
#' This function should not be run by the user. | ||
#' @noRd | ||
blsViewUI <- function() { | ||
fluidPage( | ||
## Title | ||
fluidRow(h1("BLS Viewer", style = "text-align: center;")), | ||
fluidRow(br()), | ||
|
||
## Unemployment Plot | ||
fluidRow(column(offset = 1, 10, plotlyOutput("unemploymentPlot"))), | ||
fluidRow(br()), | ||
|
||
## Selections for Series and Years | ||
fluidRow( | ||
column( | ||
offset = 2, 3, | ||
selectizeInput("unemploymentSeries", "Select Unemployment Series", | ||
choices = NULL, multiple = TRUE | ||
) | ||
), | ||
column(2, selectizeInput("selectStartYear", "Select Start Year", | ||
choices = NULL | ||
)), | ||
fluidRow(column( | ||
2, | ||
selectizeInput("selectEndYear", "Select End Year", | ||
choices = NULL | ||
) | ||
)) | ||
) | ||
) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#' @import shiny | ||
#' @import plotly | ||
#' @import RSQLite | ||
#' @import DBI | ||
#' @importFrom zoo as.yearmon | ||
#' @importFrom jsonlite fromJSON | ||
#' @importFrom utils head tail | ||
NULL |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#' Create Unemployment Plot | ||
#' | ||
#' This function should not be run by the user. | ||
#' @param series selection of unemployment series | ||
#' @param yearStart selection of start year for series | ||
#' @param yearEnd selection of end year for series | ||
#' @noRd | ||
unemploymentPlot <- function(series, yearStart, yearEnd) { | ||
## Get unemployment data from data base. | ||
unemploymentData <- blsSelect(paste0( | ||
"SELECT uiName, year, month, rate FROM blsDataSeries ", | ||
"INNER JOIN blsSeriesNames ON ", | ||
"blsSeriesNames.seriesID = blsDataSeries.fk_seriesID ", | ||
"WHERE uiName IN ('", | ||
paste(series, collapse = "','"), | ||
"') AND ", " year >= ", yearStart, " AND year <= ", yearEnd, ";" | ||
)) | ||
|
||
## If no data is found return a warning. | ||
if (nrow(unemploymentData) == 0) { | ||
warning("No Unemployment Data For Selection") | ||
return(NULL) | ||
} | ||
|
||
## Create sortable month/year formatted column. | ||
unemploymentData$yearMonth <- as.yearmon(paste( | ||
unemploymentData$month, | ||
unemploymentData$year | ||
)) | ||
unemploymentData <- unemploymentData[order(unemploymentData$yearMonth), ] | ||
|
||
## Create Plotly plot of unemployment data. | ||
blsPlot <- plot_ly(unemploymentData, split = ~uiName, | ||
x = ~yearMonth, y = ~rate, type = "scatter", mode = "lines" | ||
) %>% | ||
layout( | ||
xaxis = list(title = "Year"), | ||
yaxis = list(title = "Unemployment Rate"), | ||
title = series | ||
) | ||
|
||
return(blsPlot) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# blsBandit R Package | ||
|
||
The goal of this package is make it easy to view BLS data using Rshiny. | ||
It is currently under development and only shows the U1-U6 unemployment data. | ||
|
||
## Package Installation | ||
|
||
If needed install devtools. | ||
install.packages("devtools") | ||
Install blsBandit. | ||
devtools::install_github("Jeremy-Fitzpatrick/blsBandit") | ||
|
||
## BLS Viewer | ||
|
||
The blsViewer() function runs a simple GUI interface where the user can select | ||
an employment series. Once the employment series is selected a start and end | ||
date to be plotted in the interface can be selected. | ||
|
||
## Update Unemployment Data | ||
|
||
The updateUnemploymentData() function is used to update the unemployment data | ||
series in the database. It is only necessary if you'd like to get the latest | ||
data and will require the installation of the blsAPI package. | ||
|
||
## Released Under MIT License | ||
See LICENSE.md file. |
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.