Build interactive apps with Streamlit in Peliqan, for example to search data, make updates to data, data entry, data quality checks etc.
Streamlit is a wonderful low-code Python module to add UI components with a single line of code per component. Streamlit is built-in into Peliqan and available as the st
module.
# Show a title
st.title("My title")
# Show a text
st.text("My text")
# Show anything, e.g. a JSON object, string, DF...
st.write(my_data)
# Show a chart
st.line_chart(data)
# Load a table from Peliqan and show it as a table, JSON or DF
dbconn = pq.dbconnect('dw_123')
rows = dbconn.fetch('db_name', 'schema_name', 'table_name')
st.table(rows)
st.json(rows)
st.dataframe(rows)
button = st.button("Click me")
if button:
# do stuff when button clicked
option = st.selectbox("Please Choose", ["Email", "Home phone", "Mobile phone"])
st.write("You selected:", option)
Use a callback function to handle a selection:
def on_change():
st.text(f"Selected option: %s" % st.session_state.my_selectbox)
st.selectbox("Please choose", ["A", "B", "C"], key = 'my_selectbox', on_change = on_change)
Save selection in Peliqan state and load from state on each run:
options = ["Option 1", "Option 2", "Option 3"]
selected_option = pq.get_state()
index = None
if selected_option:
for i, option in enumerate(options):
if selected_option == option:
index = i
def on_change():
st.text(f"Selected option: %s" % st.session_state.my_selectbox)
pq.get_state(st.session_state.my_selectbox)
st.text(f"Index: %s" % index)
st.selectbox("Please choose", options, index = index, key = 'my_selectbox', on_change = on_change)