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.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.