Hi,
I have a question regarding the good practice to separate the data manipulation and layout. The code could be long and messy to have data manipulation, HTML components, CSS, streamlit widgets altogether.
According to my understanding:
- It’s possible to write the HTML in a separate file and import it into the layout file.
- It’s possible to write the normal CSS, and import and use it with markdown.
- It’s possible to share a global variable across the files that I can put data manipulation into another file.
- It’s possible to write functions separately in another file.
The question is that how could I share the output from selectbox
across two or multiple scripts?
For example, I want to get the selected_country
from app.py
, send it to the data.py
. Finally, render the data with st.text
(pseudo code):
[app.py]
import data
import streamlit as st
selected_country = st.selectbox('', data.countries, index=data.countries.index('Taiwan')) # send to data.py
st.text(f"{selected_country} vaccination rate is: {data.country_vaccination}%")
[data.py]
countries = df_vaccination_by_country.sort_values(by='location')['location'].tolist()
country_vaccination = df_vaccination_by_country\
[df_vaccination_by_country['location']==selected_country]\
['total_vaccinations_per_hundred'].values[0]