I am creating a dashboard for a data acquisition methodology consisting of multiple .py files. It’s very frequent that, in order to monitor the methodology, I need to print variables from the various .py files to the dashboard, while the values of these variables are updated inside for loops and if statements.
The issue is that when the values of the variables are updated, the output in the dashboard does not change. Example: I need to output the status code of a request. In case I get a 429 status code, I need it printed in the dashboard.
So far, I’ve tried global variables, and st.session_state but none works.
Is there some workaround?
Can you check that custom functions that you define in the multiple .py files are imported into the main app file so that they are rendered in the app which would allow the results to be displayed in app.
For example, let’s say you have
import pandas as pd
import streamlit as st
from calculations import load_data
df = load_data
From the example above, you can see that you have a created a custom function called
calculations.py and you are importing that into the main app file via
from calculations import load_data and then you’re calling the function and assigning it to a
df variable which is then displayed in the app.
Hope this helps!
Hi @dataprofessor, thank you for the reply!
The functions are imported, however, what I think is happening here is that when calling a function from different .py and variables are changed within for loops and if statements, the app gets stuck in the for loop and therefore the other parts of the app are not updated. So, in reality, even though the called function changes the variables’ values, the dashboard functions are not running and I cannot see how the variable changes with every iteration.
I’m trying to figure out a way to call the functions from these .py files, and while the variables’ change values, I can still see the change with every iteration. I am not sure it’s the correct terminology, but sort of stream messages and values in the dashboard in real-time.
Obviously I’m as stuck as the app itself in the for loop…