Module 2
digital consent form
.streamlit
.suprbase
) for you to connect to.streamlit
server that you will be building.install
libraries and then import
to use them.application process interface
(API
) is a means for computer programs to communicate with each other.supabase python library
to connect to the supabase database
via its API
.tables
.query
tables in the database to get data.State
in a web app is basically the current values of variables being used.forms
to collect user input.scope
.Scope
defines where a variable can be read and altered.Scope
is determined by where a variable was originally defined.scope.py
Output
Patient Name: Alice Smith
Traceback (most recent call last):
File "/scope.py", line 6, in <module>
print(patient_name)
^^^^^^^^^^^^
NameError: name 'patient_name' is not defined.
-1
negative_indexing.py
Output
The last patient is: David
list_comprehension.py
Output
[38.5, 39.0, 39.5]
list_comprehension.py
Output
Alice
list_function.py
Output
['name', 'hospital_number', 'age']
all()
function returns true if all elements in a list pass a certain test.all.py
Output
True
all.py
OUTPUT
ok
Streamlit
for the frontend.Direct import
or as an alias
streamlit_methods.py
import streamlit as st
# A title for the page
st.title("My first web app")
# Writes text to the browser
st.write("Text to write to browser")
# Text input field with key and on_change function
# "key_1" is stored as a key in the session state (described later)
st.text_input("label", key="key_1", on_change=lambda:on_change_function())
# Or, assign the input field results to a variable
hospital_number = st.text_input("Hospital number", "0", disabled=False)
streamlit_methods.py
Otherwise, the browser will be a little messy with all of your code visible.
(See .streamlit/config.toml file if interested)
CTRL - C
or
CMD - C
Supabase
database and then query the data.supabase.py
import streamlit as st
from st_supabase_connection import SupabaseConnection, execute_query
# Starts a connection to the cloud database on Supabase
conn = st.connection("supabase", type=SupabaseConnection)
# RETRIEVE data from database
users = execute_query(conn.table("users").select("*"), ttl="10m")
# ADD data to database
test_data = {"test_data": "Some test data"}
update_result = execute_query(
conn.table("test_upload").insert([test_data], count="None")
)
READ AND WRITE ACCESS
READ ONLY
READ ONLY
READ ONLY
READ AND WRITE ACCESS
VS Code IDE
on your own personal machines.Codespace IDE
instead.Mac
Windows
(.venv)
at the start of the command line to signify that you are in a python virtual environment.
and
and
Supabase
cloud database, you need a URL
(Uniform Resource Locator), eg website address and a secret key
.lesson_2.py
And…
to
https://letsdodigital.org/learn/learn-python/module-2/
There is no such thing as a stupid question, only a question left unanswered