🎵 Do you want to build a web app? 🎵

Module 1

Let’s Do Digital Team

What to build?

Streamlit

  • We will be using a python web app framework called Streamlit.
  • Frameworks are great, as someone else has done most of the heavy coding to make it easier for you to carry out a task (in this case building a web app).

Module import

Direct import

libraries_1.py
import streamlit

or as an alias

libraries_2.py
import streamlit as st

Who is running what?

main.py
if __name__ == "__main__":
    main()
  • Checks if the current file is being run as an imported library or directly

Streamlit methods

streamlit methods.py
import streamlit as st

# Writes text to the browser
st.write("Text to write to browser")

# Creates a text input field
# `step` is the increment for + - buttons
st.number_input("Label of input box", step=1) 

# Creates a select box
st.selectbox("Label for selectbox", ["first choice","second choice"])

magicEnabled = false

  • We have turned off a feature in Streamlit that shows all of your code in the browser using:
.streamlit/config.toml
[runner]
magicEnabled = false


(See .streamlit/config.toml file if interested)

Stopping a running program

CTRL - C

or

CMD - C

Warning!

  • You are building an educational program. This is NOT to be used with real patients!

Time to install a framework

  • You now need to install the Streamlit framework. Don’t worry, it is very easy:
$ cd lesson_3
$ pip install streamlit
  • And now run this code:
$ streamlit run exercise_1.py

Now off you go!