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.
The guidance below is for the members of the Strategy Unit’s Data Science team, who built and maintain this app.
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 the app locally on your machine to test that your changes work as expected.
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.
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:
- Open the
dev/watch.Rscript and go to the ‘Background Jobs’ tab of the console pane and click the ‘Start Background Job’ button. - Click ‘Start’ after checking that the ‘R Script’ path is
pre-populated with the path to
watch.R(otherwise select it yourself). - 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.
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:
- Merge any PRs you want to test into the
mainbranch. - If you’ve changed any dependencies, run
dev/generate_manifest.Rto updatemanifest.json. - If you’ve made any changes to the inputs selection app, run the
manual
deploy()call under the ‘development’ heading in thedeploy.Rscript 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’.
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 is controlled by GitHub Actions in .github/workflows/,
where:
- pushes to the
mainbranch 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