Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text input not getting updated after loading state from a dictionary #7084

Closed
3 of 4 tasks
raphaeltimbo opened this issue Jul 27, 2023 · 0 comments
Closed
3 of 4 tasks
Labels
feature:st.session_state feature:st.text_input priority:P2 status:confirmed Bug has been confirmed by the Streamlit team status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working

Comments

@raphaeltimbo
Copy link

raphaeltimbo commented Jul 27, 2023

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

When I try to load a state from a file, the text input in some components do not get updated if the loading time is high.

Reproducible Code Example

import streamlit as st
import time

# parameters with name and label
flow_m_units = ["kg/h", "kg/min", "kg/s", "lbm/h", "lbm/min", "lbm/s"]
flow_v_units = ["m³/h", "m³/min", "m³/s"]
flow_units = flow_m_units + flow_v_units

parameters_map = {
    "flow": {
        "label": "Flow",
        "units": flow_units,
        "help": "Flow can be mass flow or volumetric flow depending on the selected unit.",
    },
    "head": {
        "label": "Head",
        "units": ["kJ/kg", "J/kg", "m*g0", "ft"],
    },
    "eff": {
        "label": "Efficiency",
        "units": [""],
    },
    "power": {
        "label": "Gas Power",
        "units": ["kW", "hp", "W", "Btu/h", "MW"],
    },
}

plot_limits = {}
fig_dict_uploaded = {}

# add button to load state from state.json

if st.button("Load state"):
    state = {
        "x_eff_sec1_flow_units": "m\u00b3/h",
        "x_eff_sec1_lower": "0",
        "x_eff_sec1_upper": "4500",
        "x_eff_sec2_flow_units": "m\u00b3/h",
        "x_eff_sec2_lower": "0",
        "x_eff_sec2_upper": "1600",
        "x_head_sec1_flow_units": "m\u00b3/h",
        "x_head_sec1_lower": "0",
        "x_head_sec1_upper": "4500",
        "x_head_sec2_flow_units": "m\u00b3/h",
        "x_head_sec2_lower": "0",
        "x_head_sec2_upper": "1600",
        "x_power_sec1_flow_units": "m\u00b3/h",
        "x_power_sec1_lower": "0",
        "x_power_sec1_upper": "4500",
        "x_power_sec2_flow_units": "m\u00b3/h",
        "x_power_sec2_lower": "0",
        "x_power_sec2_upper": "1600",
        "y_eff_sec1_lower": "0.65",
        "y_eff_sec1_units": "",
        "y_eff_sec1_upper": "0.90",
        "y_eff_sec2_lower": "0.40",
        "y_eff_sec2_units": "",
        "y_eff_sec2_upper": "0.75",
        "y_head_sec1_lower": "20",
        "y_head_sec1_units": "kJ/kg",
        "y_head_sec1_upper": "160",
        "y_head_sec2_lower": "0",
        "y_head_sec2_units": "kJ/kg",
        "y_head_sec2_upper": "90",
        "y_power_sec1_lower": "0",
        "y_power_sec1_units": "kW",
        "y_power_sec1_upper": "8000",
        "y_power_sec2_lower": "0",
        "y_power_sec2_units": "kW",
        "y_power_sec2_upper": "4500",
    }
    st.session_state.update(state)


for curve in ["head", "eff", "power"]:
    st.markdown(f"### {parameters_map[curve]['label']}")
    parameter_container = st.container()
    first_section_col, second_section_col = parameter_container.columns(2, gap="small")
    plot_limits[curve] = {}
    # create upload button for each section
    for section in ["sec1", "sec2"]:
        plot_limits[curve][section] = {}
        if section == "sec1":
            section_col = first_section_col
        else:
            section_col = second_section_col

        # add time.sleep to simulate long loading time
        time.sleep(1)

        # add container to x range
        for axis in ["x", "y"]:
            with st.container():
                (
                    plot_limit,
                    units_col,
                    lower_value_col,
                    upper_value_col,
                ) = section_col.columns(4, gap="small")
                plot_limit.markdown(f"{axis} range")
                plot_limits[curve][section][f"{axis}"] = {}
                plot_limits[curve][section][f"{axis}"][
                    "lower_limit"
                ] = lower_value_col.text_input(
                    f"Lower limit",
                    key=f"{axis}_{curve}_{section}_lower",
                    label_visibility="collapsed",
                )

                plot_limits[curve][section][f"{axis}"][
                    "upper_limit"
                ] = upper_value_col.text_input(
                    f"Upper limit",
                    key=f"{axis}_{curve}_{section}_upper",
                    label_visibility="collapsed",
                )

                if axis == "x":
                    plot_limits[curve][section][f"{axis}"][
                        "units"
                    ] = units_col.selectbox(
                        "flow units",
                        options=parameters_map["flow"]["units"],
                        key=f"{axis}_{curve}_{section}_flow_units",
                        label_visibility="collapsed",
                    )
                else:
                    plot_limits[curve][section][f"{axis}"][
                        "units"
                    ] = units_col.selectbox(
                        f"{curve} units",
                        options=parameters_map[curve]["units"],
                        key=f"{axis}_{curve}_{section}_units",
                        label_visibility="collapsed",
                    )

Steps To Reproduce

  1. Run the app with time.sleep(0) to see the expected behavior;
  2. After starting the app, click the load button;
  3. Notice that every text input has been updated according to the state dictionary;
  4. Change time.sleep(1) to simulate a long loading time;
  5. Refresh the app with ctrl + shift + r so that all text input are empty;
  6. Click the load button;
  7. Notice that some text inputs will remain empty.

Expected Behavior

I expected that, independently of the time.sleep parameter, all the text input would be correctly updated.

App after clicking the load button with time.sleep(0) (Expected behavior):

image

Current Behavior

App after clicking the load button with time.sleep(1), where some text inputs do not get updated:

image

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.25
  • Python version: 3.10.9
  • Operating System: Windows 10
  • Browser: Firefox

Additional Information

No response

@raphaeltimbo raphaeltimbo added status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working labels Jul 27, 2023
@raphaeltimbo raphaeltimbo changed the title Text input not getting updated after loading state from a file Text input not getting updated after loading state from a dictionary Jul 27, 2023
@willhuang1997 willhuang1997 added status:confirmed Bug has been confirmed by the Streamlit team priority:P2 labels Aug 10, 2023
sfc-gh-wihuang pushed a commit that referenced this issue Aug 12, 2023
#7150)

Describe your changes
Change commitWidgetValue to take in dirty parameter as we need to change dirty to true when committing the widget value
we need to commit the widget value because when autofill is done, the widget value is not committed as thus username will show up to be an empty string without interaction
GitHub Issue Link (if applicable)
#7101
#7084

Testing Plan
Explanation of why no additional tests are needed
Unit Tests (JS and/or Python)
readded tests I deleted before with some slight additions
E2E Tests
Any manual testing needed?
yes
it doesn't seem very doable to test autofill functionality. However, I can probably add some tests for commit value being called
Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
eric-skydio pushed a commit to eric-skydio/streamlit that referenced this issue Dec 20, 2023
streamlit#7150)

Describe your changes
Change commitWidgetValue to take in dirty parameter as we need to change dirty to true when committing the widget value
we need to commit the widget value because when autofill is done, the widget value is not committed as thus username will show up to be an empty string without interaction
GitHub Issue Link (if applicable)
streamlit#7101
streamlit#7084

Testing Plan
Explanation of why no additional tests are needed
Unit Tests (JS and/or Python)
readded tests I deleted before with some slight additions
E2E Tests
Any manual testing needed?
yes
it doesn't seem very doable to test autofill functionality. However, I can probably add some tests for commit value being called
Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
zyxue pushed a commit to zyxue/streamlit that referenced this issue Mar 22, 2024
streamlit#7150)

Describe your changes
Change commitWidgetValue to take in dirty parameter as we need to change dirty to true when committing the widget value
we need to commit the widget value because when autofill is done, the widget value is not committed as thus username will show up to be an empty string without interaction
GitHub Issue Link (if applicable)
streamlit#7101
streamlit#7084

Testing Plan
Explanation of why no additional tests are needed
Unit Tests (JS and/or Python)
readded tests I deleted before with some slight additions
E2E Tests
Any manual testing needed?
yes
it doesn't seem very doable to test autofill functionality. However, I can probably add some tests for commit value being called
Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
zyxue pushed a commit to zyxue/streamlit that referenced this issue Apr 16, 2024
streamlit#7150)

Describe your changes
Change commitWidgetValue to take in dirty parameter as we need to change dirty to true when committing the widget value
we need to commit the widget value because when autofill is done, the widget value is not committed as thus username will show up to be an empty string without interaction
GitHub Issue Link (if applicable)
streamlit#7101
streamlit#7084

Testing Plan
Explanation of why no additional tests are needed
Unit Tests (JS and/or Python)
readded tests I deleted before with some slight additions
E2E Tests
Any manual testing needed?
yes
it doesn't seem very doable to test autofill functionality. However, I can probably add some tests for commit value being called
Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:st.session_state feature:st.text_input priority:P2 status:confirmed Bug has been confirmed by the Streamlit team status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants