I have a pretty long code (calculating pore pressure and frac gradient for oil and gas) and it has a variable bank of different pressures of certain rock formations.
I want the user to be able to input a pressure on the app that re-runs my code using the user input instead of the standard variable in the back-end code.
Any ideas? I chose not to post the code since it’s +800 lines…
All of the Streamlit widgets take a default value, so depending on the scale/granularity of what that constant can be, you could do something like:
porepress = st.slider("Choose pore pressure to simulation", 0, 100, 5)
# way later in code
val = pressure(porepress)
That way, on first load, the user would get the default value (in this toy example, 5), and then they can choose whatever value is appropriate for their scenario.
Thanks a lot for your reply! I actually got it running with session_state (which I am a novice at). Here is how I coded 4 user input variables that would override my default pressure variables.
with col1.expander("Low Side Pore Pressure Inputs (PSI)"):
if 'Low Side Inyan Kara' not in st.session_state:
LS_inyan_kara = st.number_input('Low Side Inyan Kara', value = 3200)
if 'Low Side Amsden' not in st.session_state:
LS_20_high_amsden = st.number_input('Low Side Amsden', value = 0)
if 'Low Side Frobisher-Alida' not in st.session_state:
LS_300_low_rival = st.number_input('Low Side Frobisher-Alida', value = 0)
if 'Low Side Upper Bakken' not in st.session_state:
LS_upper_bakken = st.number_input('Low Side Upper Bakken', value = 8400)
```
@randyzwitch here is my next issue which i’ve spent 2 days on…
I have a simple dataframe based on a small csv that I import to Streamlit with the drag and drop function. I’m utilizing AgGrid to make the dataframe editable. The only problem is that I cannot get st.session_state to save the updated dataframe when i refresh or navigate to another page in the app. Any suggestions? To display the editable dataframe is on line of code as follows:
def topset_data_editable2():
global df_topset
j = AgGrid(df_topset, editable = True)
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.