/Shiny-App-NBA

An R Shiny application to demonstrate various features & best practise.

Primary LanguageRGNU General Public License v3.0GPL-3.0

Shiny App with NBA Data

Lifecycle: experimental

This application demonstrates various features of R & Shiny development.

Installation

This package is currently private only. If you have been given access on GitHub please follow the instructions below:

devtools::install_github("James-G-Hill/shiny-app-nba")

Features

Here is a list of notable features of the application:

  • Written as R package with DESCRIPTION file & appropriate directory structure
  • Written as a golem package with appropriate structure
  • Written to shiny standards including shiny modules & reactive components
  • Source control via Git
  • Package management with renv
  • ‘Stats’ page team & season variables managed with config file
  • Added example test with testthat
  • Added example shinytest script (although see related section below)
  • Written to standards of Tidyverse Style Guide
  • Documentation of functions with roxygen2
  • GUI created with bs4Dash demonstrating BootStrap 4
  • Interactive charts with esquisse
  • Interactive tables with DT
  • Chart created with ggplot2
  • Themed with fresh
  • Further detailed theming through custom css
  • Added tooltips with css
  • Added demonstration of calls to Javascript to switch tabs from Help tab
  • Preloader configured with waiter
  • Includes Rmarkdown to split, clean, & conform original data source
  • Favicon created with hexSticker

View the App

You may be able to see the application at the following webpage:

Shiny NBA Free Throws

Note that I do not regularly check the app is still available. It should work but it is possible that the service providers stops it. If the link fails then please contact me so that I can restart it.

Development Setup

In order to work on this application locally you will need the dataset. First, you will need to download the dataset from the following link:

NBA Free Throws

Then place the dataset in the ‘dev/data/source_data’ directory. You will then need to open and run the split_data.Rmd script. This will create the data in the ‘dev/data/app_data’ directory.

You can then test the app locally with the following command:

golem::run_dev()

Changing Team & Season

The Stats tab has the team & season controlled by a configuration file. This has been enabled to demonstrate the capability. The file can be found at ‘inst/golem-config.yml’.

The following options can be updated:

  • team : A short code for the team
  • season : A season in the format: ‘yyyy - yyyy’
  • team_color_1 : A team hex color for the banner
  • team_color_2 : Another team hex color for the banner

Team colors can be found at the following link:

NBA Team Colors

Running on shinyapps.io

  1. Create an account at ‘www.shinyapps.io’
  2. Install ‘rsconnect’ package (install.packages('rsconnect'))
  3. Follow the instructions for authorizing an account
  4. Load the library ‘rsconnect’ locally (library('rsconnect'))
  5. Deploy with rsconnect::deployApp('path/to/your/app')

shinytest

I recorded a shinytest to demonstrate that I am capable of doing so. However, recording this package & the tests with the finished package will fail. There are 2 current issues which are beyond easy resolution:

  • phantomJS won’t record with the esquisse package loaded
  • testing currently won’t identify the bs4Dash::sidebarMenu id

The phantomJS issue maybe a result of that package no longer being developed. The sidebarMenu ‘id’ issue seems like it should be resolved:

bs4Dash Issue

I was unable to get it to work even though the ‘id’ being available in app. With further time I would investigate further & raise the second issue again.

Further Development

This application was developed to demonstrate Shiny features. I therefore did little development of the data due to time constraints. A deep review of the data with full cleaning would be necessary with more time.

It is also not easy (& consistent) to identify the team for a player. A list of players per team per season would allow for stats per team per game. As is, the data only allows to analyse free throws across both teams per game. This limits the strategic analysis possible.

Known Issues

The esquisse package interactive chart doesn’t work on tested iPad.

Attribution

This package uses a free ‘basketball’ icon provided by Font Awesome. The icon .svg file has been modified so the colour is white. Please find the link to the license here:

https://fontawesome.com/license