User input that overwrites a numerical variable in my code?

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…

Hi @jacobrsmith37, welcome to the Streamlit community!

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.

Best,
Randy

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)

My dataframe from the csv is df_topset

@randyzwitch any ideas? I’ve been stuck on this for a long time!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.