Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recreate SRO Liver Function Testing key measure with Streamlit #19

Merged
merged 1 commit into from
Jan 2, 2025

Conversation

iaindillingham
Copy link
Member

@alarthast and I worked together on this solution to recreate the SRO Liver Function Testing key measure with Streamlit.

Alice, I'd like to highlight the architecture of the solution. app/sro_key_measures.py is the presentation (application) layer; it constructs the user interface. app/measures.yaml is, very loosely, the persistent storage (database) layer. Sitting between the two is a repository (OSJobsRepository), which constructs domain model objects (Measure) using information from the persistent storage layer and passes them to the presentation layer. You can find out more about layers, repositories, and domain model objects in Chapters 1 and 2 of Architecture Patterns with Python.

I'm still learning about layers, repositories, and domain model objects myself, so we shouldn't assume that the solution is the only solution 🙂. However, I think that a well-defined architecture is going to help us iterate quickly.

You many have noticed the following:

PYTHONPATH=. {{ STREAMLIT }} run {{ args }}

Streamlit Community Cloud seems to set PYTHONPATH to the directory within which the "main file" is located, which in this case is app/sro_key_measures.py. However, it's more convenient for PYTHONPATH to be the project root directory. Imports are then relative to the project root directory...

from app import measures

...which makes interacting with code in a REPL, such as IPython, less faffy. However, when we deploy the app, we must remember to set PYTHONPATH. It looks like the mechanism for doing so is the same as that for managing secrets.

You asked why I decided not to nest the various URLs in app/measures.yaml. That is, why this...

- name:
  codelist_url:
  counts_table_url:
  top_5_codes_table_url:
  deciles_table_url:

...rather than this...

- name:
  urls:
    codelist:
    counts_table:
    top_5_codes_table:
    deciles_table:

I took the Zen of Python's advice that "Flat is better than nested." (import this). Thinking about it more, though, I don't think there's any reason why these URLs need to be grouped: We don't, for example, group strings or integers; or OS Jobs URLs and OpenCodelists URLs. So, I decided not to nest the various URLs. The flat structure of each record in app/measures.yaml is also consistent with the flat structure of Measure.

Closes #2

@iaindillingham iaindillingham merged commit c763dda into main Jan 2, 2025
1 check passed
@iaindillingham iaindillingham deleted the iaindillingham/test-streamlit branch January 2, 2025 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Recreate SRO Liver Function Testing key measure with Streamlit
2 participants