A first web app#
The creation of a web application is all handled “behind the scenes” by the streamlit
software. A user needs to write a streamlit
script that specifies placement of widgets on the screen.
1. A reminder of how to use the model#
Below is the basic script we create to use the model wrapper functions.
from model import Experiment, multiple_replications
# set number of resources
n_operators = 13
n_nurses = 9
# set chance of nurse
chance_callback = 0.4
# set number of replications
n_reps = 5
# create experiment
exp = Experiment(n_operators=n_operators, n_nurses=n_nurses,
chance_callback=chance_callback)
# run multiple replications of experment
results = multiple_replications(exp, n_reps=n_reps)
# show results
results.describe()
01_mean_waiting_time | 02_operator_util | 03_mean_nurse_waiting_time | 04_nurse_util | |
---|---|---|---|---|
count | 5.000000 | 5.000000 | 5.000000 | 5.000000 |
mean | 2.791417 | 92.105187 | 39.512995 | 96.800153 |
std | 0.912102 | 1.772361 | 11.117251 | 0.708716 |
min | 1.634700 | 90.108331 | 23.970179 | 96.065088 |
25% | 2.622755 | 91.298766 | 37.424467 | 96.325704 |
50% | 2.696908 | 91.666991 | 38.937995 | 96.521772 |
75% | 2.814228 | 92.611987 | 42.198773 | 97.371930 |
max | 4.188494 | 94.839861 | 55.033562 | 97.716269 |
2. Modifying the script: import streamlit
and create a title#
The first step is to add the following import at the top of the module:
import streamlit as st
If we rename and save model.py
as basic_app.py
we can then run it using the following from the command line
streamlit run basic_app.py
The web app will run at the following address and port: http://localhost:8501
If the app does not launch automatically you can paste into your browser.
This will present you with a very unexciting blank canvas!
Go back to basic_app.py
and add in the following code to create a page title
st.title("Urgent care call centre")
Tip: you can leave the app running while you do this. Just save the file and the app will prompt you to reload it as changes have been made.
4. Next steps.#
Next we will look at how we use streamlit
input widgets to make our simulation interactive.