i need the ability to read string(full function block) and display the result
for the matter it can be anything the function can be just temp_df = pd.read_sql(âsome tableâ) and do st.dataframe( temp_df)
I would highly recommend either removing exec altogether, or at a minimum isolating it down to just the minimal amount of code that you actually need.
If youâre reading a separate file in as a string, you should just be able to import that file to run it. Or else, you can put the code you want to run into a function inside that file, import the function, and run that.
The error message is telling you why your expected behavior cannot occur and hints at possible ways to fix the problem. Is there something you donât understand?
The string contains variables specific to execute the function, and the function itself
Letâs say I have 2,3 function that I want to show and than execute the function using EXEC()
Is it nor possible to achieve in streamlit?
Use the functions inline with the Streamlit code (assuming you are in control of, or own these functions). If you canât control or bind the variable values in these functions within the Streamlit app, then build a simple API wrapper to execute the functions and return results (this is just half a dozen lines of code using FastAPI). Then call this API from your Streamlit app. Because the execution lifecycle of Streamlit apps and the lifecycle of a separate executing processes or thread (your exec fork) is not a natural fit, you ought to separate them, rather than try to glue them together. Thatâs the simplest way to do this IMO.