Currently i deploy my streamlit app on a company server using windows-tasks and a batch file like that:
@ECHO OFF
set root=C:\Users\...\Miniconda3
call %root%\Scripts\activate.bat
cd C:/Users/.../PycharmProjects/pythonProject
call streamlit run main.py --server.headless true --server.port 8501
Everyone with access to the machine can reach the site just fine. I was just wondering if that is the “right way” of deploying the app.
One thing i noticed, is that the multi-user experience is not smooth. For example the site-setting is set to wide, once the site is refreshed in the browser it goes to narrow-mode and i have to manually reset it to wide-mode.
Also what happens with caches of different users? Can they get mixed up, or reset? For example i use
st.cache_data.clear()
in one of my apps. Will that wipe the cache for all users?
Is there any way to set a distinct url in the server settings and not just the port?
st.set.page_config() goes into my main.py as the first command?
Now that would be a big problem for me. Is there a workaround to make a “user-cache” The cache consists of the results of a heavy sql query and data cleanup function. Each user can select different data and a different querry.
if 'nlp' not in st.session_state:
st.session_state.nlp = initSpacy()
if 'dataSubmitted' not in st.session_state:
st.session_state.dataSubmitted = pd.DataFrame()
if 'dataUpdated' not in st.session_state:
st.session_state.dataUpdated = pd.DataFrame()
if st.form_submit_button("Los"):
st.cache_data.clear()
st.session_state.firstRun = False
st.session_state.dataSubmitted = fetchData(st.session_state.nlp)
st.session_state.dataUpdated = st.session_state.dataSubmitted
@st.cache_data()
def fetchData(_nlp):
with st.spinner("SQL Abfrage läuft..."):
# SQL Abfrage
data = importDataFromSQLSImilarity(auchGeschlossene,nurGeschlosseneFehler, nrows, zeitraum, modul)
text = str(data.shape[0])+" Datensätze werden bereinigt..."
with st.spinner(text):
# Bereinigung des Textes
data = cleanUpData(data,_nlp)
text2 = "Tokens für "+str(data.shape[0]) + " Datensätze werden erzeugt..."
with st.spinner(text2):
# Tokenizing und anschlieĂźend Neusortieren der Spalten
data = tokenizeData(data,_nlp)
return data
So lets say User A selects some data through the app which is saved as the session_state. When User B connects to the site from a different machine an hits the submit-button, will that not clear the data from user A?
Note that there’s no users in your code, the application has no way to tell users apart from each other. So there are no user data. There are sessions. Data in session_state last until the session ends, cached data last until the application exits.