Treatment sim streamlit app#
In this exercise you will incrementally build up a simple streamlit app for the treat_sim package. The app will allow a user to set input parameters using sliders, run the simulation model and view a results summary.
It is recommended that you use basic treat_sim script that has already been provided.
Exercise 1#
Create a a basic streamlit app with a title and information.
Create a new file called
my_streamlit_app.py; copy and paste in the code from main.pyBegin to convert this into a streamlit app
Import
streamlitAdd a streamlit title (e.g. “Treatment Simulation model”)
Read in and display the markdown text from
resources/overview.mdOr create the file yourself. Use the following text:
**A simple simulation model of a urgent care and treatment centre.**
* Change the model parameters and rerun to see the effect on waiting times and utilisation of rooms.
Use
st.spinnerandst.successto provide feedback about the model.Run the app as follows
streamlit run my_streamlit_app.py
Basic treat_sim script#
'''
Script to complete a basic run of the model and display a table of
results.
The model is imported from a pypi package 'treat_sim'
Full documentation and source code for `treat_sim` is available as
* Jupyter Book: https://tommonks.github.io/treatment-centre-sim/
* github: https://github.com/TomMonks/treatment-centre-sim
A conda environment has been provided locally,but the model can be pip installed
`pip install treat_sim==1.0.0`
This will be adapted into a basic streamlit app
'''
from treat_sim.model import Scenario, multiple_replications
# set the variables for the run.
# these are just a subset of the total available for this example...
n_triage = 1
n_exam = 3
n_cubicles_1 = 1
# examination mean
exam_mean = 16.0
# runs
replications = 10
# Setup scenario using supplied variables
args = Scenario(n_triage=n_triage, n_exam=n_exam, n_cubicles_1=n_cubicles_1,
exam_mean=exam_mean)
# run multiple replications of the model.
results = multiple_replications(args, n_reps=replications)
# print mean results.
print(results.mean().round(1))
00_arrivals 223.9
01a_triage_wait 35.3
01b_triage_util 0.6
02a_registration_wait 107.0
02b_registration_util 0.8
03a_examination_wait 27.5
03b_examination_util 0.8
04a_treatment_wait(non_trauma) 141.6
04b_treatment_util(non_trauma) 0.9
05_total_time(non-trauma) 240.2
06a_trauma_wait 100.4
06b_trauma_util 0.8
07a_treatment_wait(trauma) 199.9
07b_treatment_util(trauma) 0.9
08_total_time(trauma) 418.1
09_throughput 151.5
dtype: float64
Exercise 2:#
Update parameters and run the simulation model via the app
Convert the hard coded parameter values into
streamlitsliders.Set the script up to that
streamlitruns the simulation only when aRun Simulationbutton is clicked.Using
st.tableorst.dataframedisplay the results of the simulation model to a user.
Exercise 3:#
Add in a side bar that display the sliders to a user
Create a side bar section in your app and add in the slider.
Run your model and check it still works.
Exercise 4:#
Research streamlit pages
Read the documentation on streamlit pages.
Add in an “about page”.