Skip to content

Repository files navigation

NHP Inputs

Project Status: Active – The project has reached a stable, usable state and is being actively developed. check

About

A web app to input the parameters needed to run scenarios through the New Hospital Programme (NHP) demand model.

The app is deployed to Posit Connect. You must have an account and sufficient permissions to view it.

Results can then be viewed in the outputs app, which is generated from the nhp_outputs repository.

You can find more information on the NHP model project information site, including a diagram of how the components of the modelling process fit together.

For developers

The guidance below is for the members of the Strategy Unit’s Data Science team, who built and maintain this app.

Structure

Technically there are two apps: the main app in the main branch, and the inputs selection app (where users start or edit a scenario). Users arrive at the selection app before being routed to the main app.

Both apps are built with Shiny and the main app uses the the {golem} package. Server and UI modules can be found in R/, configuration in inst/golem-config.yml and supporting data and text in inst/app/.

Run locally

Run the app locally on your machine to test that your changes work as expected.

Setup

First, install the required packages listed in the DESCRIPTION with pak::local_install_dev_deps(dependencies = TRUE).

Then add an .Renviron file to the project root that contains the required environment variables. Copy into it the required variables, which are listed in the .Renviron.example. You can get the values you need from a member of the Data Science team.

Run the app

Once setup, we can run the app. This is done by launching a background Shiny app and then watching the files for changes, which causes an auto-reload. The method for doing this depends on your IDE.

In RStudio:

  1. Open the dev/watch.R script and go to the ‘Background Jobs’ tab of the console pane and click the ‘Start Background Job’ button.
  2. Click ‘Start’ after checking that the ‘R Script’ path is pre-populated with the path to watch.R (otherwise select it yourself).
  3. When ready, a message will tell you to visit http://127.0.0.1:9081/ in your browser.

In Positron: run source('dev/watch.R') and click the link to the URL when complete.

In VS Code: open the command palette (Ctrl+Shift+P), search for ‘Tasks: Run Task’, then select ‘R: Run App (watch)’ and finally click the link to the URL when complete.

Making selections in the app will cause values to be written to a local json file, which will live in your local params/development/ directory. These scenarios will be selectable and editable in future from your locally-run inputs selection app. They will not be available from the deployed app.

Test in dev

During pre-release QA we test both apps on the server. This helps us spot any issues that are server-specific and might be overlooked if running the apps locally.

To test the unreleased app in our development environment:

  1. Merge any PRs you want to test into the main branch.
  2. If you’ve changed any dependencies, run dev/generate_manifest.R to update manifest.json.
  3. If you’ve made any changes to the inputs selection app, run the manual deploy() call under the ‘development’ heading in the deploy.R script in your selection-app development branch.

When using the dev inputs selection app on Connect, make sure to set the ‘Model Version’ dropdown to ‘dev’ in the expandable ‘Advanced Options’ box. That way you’ll be taken to the dev inputs app when you hit ‘Start’.

Data

The app displays trust-specific data to users. The data is processed via Databricks scripts in the nhp_data repository and stored in Azure storage.

If the data updates and you need to invalidate the current cache, you force a reset by appending ?reset_cache=true to the app’s canonical URL at https://connect.strategyunitwm.nhs.uk/nhp/inputs/ (authorised devs only).

Deployment

Deployment is controlled by GitHub Actions in .github/workflows/, where:

  • pushes to the main branch redeploy the app to /nhp/dev/inputs/ for purposes of quality assurance
  • tagged releases trigger a new deployment to /nhp/vX-Y/inputs/, where ‘vX-Y’ is the current version (note the hyphen)
  • manual deployment is possible with connect-publish-manual.yaml

About

Shiny app: input parameters for the New Hospital Programme (NHP) demand model

Topics

Resources

Stars

1 star

Watchers

4 watching

Forks

Releases

Used by

Contributors

Languages