the use of r shiny at the u.s. bureau of labor...

20
1 U.S. BUREAU OF LABOR STATISTICS bls.gov The Use of R Shiny at the U.S. Bureau of Labor Statistics Brandon Kopp Research Psychologist U.S. Bureau of Labor Statistics The Use of R in Official Statistics (uRos) Conference 13 September 2018

Upload: others

Post on 02-Jun-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

1 — U.S. BUREAU OF LABOR STATISTICS • bls.gov

The Use of R Shiny at the U.S. Bureau of Labor Statistics

Brandon KoppResearch Psychologist

U.S. Bureau of Labor Statistics

The Use of R in Official Statistics (uRos) Conference13 September 2018

Page 2: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

2 — U.S. BUREAU OF LABOR STATISTICS • bls.gov

Abstract

Economists and statisticians at the U.S. Bureau of Labor Statistics (BLS) have developed several RShiny applications that are or will soon be used at various points throughout the survey lifecycle.The National Compensation Survey is nearing completion on an app that will allow fieldsupervisors to monitor the progress of data collection at the national, regional, and state levels.The Producer Price Index uses an app which provides time series and other visualizations to aidin data review. The Consumer Expenditure Survey has developed an app that allowsstakeholders to view key data quality metrics such as response rates and imputation rates overtime. The Office of Publications is working on a system that will automatically generate newsrelease statements from structured data tables. In this presentation, I will show examples ofhow these applications are or will be used and discuss challenges we have encountered indeveloping and deploying these applications. I will discuss the use of R-Portable as a workaroundfor deploying applications within an organization.

Page 3: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

3 — U.S. BUREAU OF LABOR STATISTICS • bls.gov

Outline

0 2 4 6 8 10 12 14

Intro to the Use of R at BLS

R Shiny Applicationsat BLS

Shiny Deployment Without a Server

Other Uses of R at BLS

Minutes

Page 4: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

4 — U.S. BUREAU OF LABOR STATISTICS • bls.gov

Intro to the Use of R at BLS

n The Bureau of Labor Statistics (BLS) is one of 13 principal U.S. federal statistical agencies (~2,000 employees)

n Collects and disseminates data on labor market activity, working conditions, and price changes

n R is NOT approved for production activities � We primarily use SAS for production� R is used for some research and assistance activities

n 73 R projects at various points in development

Page 5: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

Collection

Processing Dissemination

MonitoringAnalysis

Not Available(Yet)

Page 6: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

NCS Response Appn Office: National

Compensation Surveyn Audience: Internaln Data Source: Data Collection

Management Systemn Use: Monitor the progress of

data collection in (near) real-time

n Status: In Developmentn Packages Used: leaflet,

highcharter, plotly

Page 7: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

PPI Visualization Dashboard

n Office: Producer Price Indexn Audience: Internaln Data Source: Pre-Release

Databasen Use: Provide context for

current month’s data for the purpose of data review

n Status: In Usen Packages Used: Roracle,

highcharter, shinydashboard

Page 8: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

OES Data Map

n Office: Occupational Employment Statistics

n Audience: Externaln Data Source: Public Data

Tablesn Use: Disseminate

employment and wage data with an easy-to-navigate interface.

n Status: Awaiting Approvaln Packages Used: leaflet, DT

Page 9: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

Next-Gen News Release Statement Generator

n Office: Office of Publicationsn Audience: Internaln Data Source: BLS Public APIn Use: Generate and display

news release style statements based on BLS public data

n Status: In Developmentn Packages Used: blsAPI, rvest,

stringr

Page 10: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

CE Data Quality Profile Dashboard

n Office: Consumer Expenditure Survey

n Audience: Internaln Data Source: Post-Analysis

Summary Tablesn Use: Monitor time series of

data quality metricsn Status: In Usen Packages Used:

shinydashboard, highcharter

Page 11: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

11 — U.S. BUREAU OF LABOR STATISTICS • bls.gov

Challenges

nApps for External Customers (website visitors/data users)� Publication standards (accessibility, branding)� Data security� Server software updates and downtime� Host ourselves or use external service

nApps for Internal Customers (analysts/managers)� Connection to databases� Authentication/Access

Page 12: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

12 — U.S. BUREAU OF LABOR STATISTICS • bls.gov

Deploying R Shiny Apps

n BLS is working on getting internally and externally facing R Shiny Servers, but we don’t have them yet

n For internal apps, we developed a workaround that allows us to deploy apps without a server

PPI Visualization Dashboard NCS Response App CE DQP Dashboard

Page 13: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

Serverless Deploymentn R-Portable (SourceForge.net)n Allows user to run a Shiny app like

it’s an application on their computer

n We run this on Windows so use a Visual Basic Script to run R-Portable and the app

n App opens in the web browsern Uses local computer resources to

run the appn Users do not have to install R or

install packages

Packages

Appui.Rserver.Rglobal.R

R-Portable

dplyr…

www

runShiny.vbs

log.txt

R.exe

Page 14: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

Remote

Packages

Appui.Rserver.Rglobal.R

dplyr…

www

A Better Way

Local

R-Portable

runShinyApp.R

runShiny.vbs

log.txt

R.exe

Page 15: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

Code From Files

n runShiny.vbs

n runShinyApp.R

n server.R (add to end of server.R file or server section of the app.R file in your Shiny Application)

CreateObject("Wscript.Shell").Run "R-Portable\bin\R.exe CMD BATCH --vanilla --slave runShinyApp.R log.txt" & " " & RND & " ", 0, False

.libPaths(<PATH TO PACKAGES DIRECTORY>)shiny::runApp(appDir = "<PATH TO SHINY APP DIRECTORY>",launch.browser=T)

#### CLOSES R WHEN BROWSER WINDOW IS CLOSED ####session$onSessionEnded(function() {

tools::pskill(Sys.getpid()) #Ends R session})

This is the code used in the files listed on the previous slide.

Page 16: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

16 — U.S. BUREAU OF LABOR STATISTICS • bls.gov

Centralized Deploymentn Users just have to drag a folder to

their computern Developers can update the

application without users needing to download again

n Helps with version control of the app and packages

n You could use a single instance of R-Portable to run several apps (just not simultaneously)

Shared Drive

Users

Remote

Local Local Local

Page 17: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

17 — U.S. BUREAU OF LABOR STATISTICS • bls.gov

Other Features

n R Console Output� Can be used for troubleshooting

nAuthentication/Access� Require a user login/password to enter or use the app� Requires additional considerations about security

nUser Logging/Audit Trail� Keep a centralized record of who has used the app for auditing

purposes but also for analytics

Page 18: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

18 — U.S. BUREAU OF LABOR STATISTICS • bls.gov

Review

n Cheap and (relatively) easyn You can replicate most of the common features of a servern The two-folder setup is ideal

nWorks great within an organization, but doesn’t work for external customers

n Some users find it non-intuitive at first

Page 19: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

19 — U.S. BUREAU OF LABOR STATISTICS • bls.gov

Other Uses of R at BLS

n R Users Group (80+ members)� Project Presentations, Tutorials, and Code Labs

n Internal Code Sharing Using GitLab

n Classes� In-Person and Online

n Package Development� rpms, growfunctions, growcurves

Page 20: The Use of R Shiny at the U.S. Bureau of Labor Statisticsr-project.ro/conference2018/presentations/Brandon_Kopp_shiny.pdf · ServerlessDeployment nR-Portable (SourceForge.net) nAllows

Contact Information

20 — U.S. BUREAU OF LABOR STATISTICS • bls.gov

Brandon KoppResearch Psychologist

Office of Survey Methods Researchwww.bls.gov/osmr

(202) [email protected]