-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
124 lines (80 loc) · 6.1 KB
/
Copy pathREADME.Rmd
File metadata and controls
124 lines (80 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# NHP Inputs
<!-- badges: start -->
[](https://www.repostatus.org/#active)
[](https://github.com/The-Strategy-Unit/nhp_inputs/actions/workflows/check.yaml)
<!-- badges: end -->
## 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](https://connect.strategyunitwm.nhs.uk/nhp/inputs/).
You must have an account and sufficient permissions to view it.
Results can then be viewed in [the outputs app](https://connect.strategyunitwm.nhs.uk/nhp/outputs/), which is generated from the [nhp_outputs](https://github.com/The-Strategy-Unit/nhp_outputs) repository.
You can find more information on [the NHP model project information site](https://connect.strategyunitwm.nhs.uk/nhp/project_information/), including [a diagram](https://connect.strategyunitwm.nhs.uk/nhp/project_information/project_plan_and_summary/components-overview.html) 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](https://the-strategy-unit.github.io/data_science/), 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) in the `inputs_selection_app` branch.
Users arrive at the selection app before being routed to the main app.
Both apps are built with [Shiny](https://shiny.posit.co/) and the main app uses the [the {golem} package](https://thinkr-open.github.io/golem/).
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_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.
Then, from the `main` branch (or your development branch of it), use Git's `worktree` function to put the `inputs_selection_app` branch (or your development branch of it) in its own subfolder.
In the terminal:
```
git fetch origin inputs_selection_app
git worktree add inputs_selection_app inputs_selection_app
```
The first argument is the name of the folder in which to put the branch content.
If you want a development version of the inputs selection app, you can specify the branch name as the second of the arguments to `git worktree add`.
If you need to remove the selection-app folder at any point, you can terminate the background job (if running) and in the terminal run:
```
git worktree remove inputs_selection_app
```
#### 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 (<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>), 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](https://github.com/The-Strategy-Unit/nhp_data) 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`