question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: text_input with caching

See original GitHub issue

Summary

Using a cached value as text_input value, text doesn’t get updated unless focus changes. I use caching a lot to support more complicated scenarios.

Steps to reproduce

2- write something hit enter 3- write something else (without changing focus) hit enter

Code snippet:

import streamlit as st
from streamlit.report_thread import get_report_ctx
    
def query_cache(q=None):
    ctx = get_report_ctx()
    session_id = ctx.session_id
    session = st.server.server.Server.get_current()._get_session_info(session_id).session
    if not hasattr(session, "_query_state"):
        setattr(session, "_query_state", "default")
    if q is not None:
        session._query_state = q
    return session._query_state

# if st.button('reset'):
#     value = ""
#     query_cache("")
value = query_cache()    
my_input=st.text_input("Input", value)
c=query_cache(my_input)
st.write(c)

Expected behavior:

should work the same as text_input without caching.

Actual behavior: 1- type ‘poo’ enter 2- type ‘poop’ enter (doesn’t update result, loses focus) 3- after focus change write ‘poop’ again. It works

streamlit-streammy-2021-04-14-18-04-68

Is this a regression?

no

Debug info

  • Streamlit version: 0.80.0
  • Python version: 3.6.9
  • OS version: ubuntu 18.04
  • Browser version: chrome & firefox latest

Additional information

I’m caching the text_input values because I want to have a button clear them (commented out in code example) Solutions that don’t use caching and also allow me to reset with a button, while also being not buggy with text_input are also welcome.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
btjones-mecommented, Sep 3, 2021

Hi folks, even using the workaround with session state I find the same issue


        state = st.session_state
        if "_pm" not in st.session_state:
            state._pm = 1.0

        proximity_modifier = st.number_input('proximity_modifier', step=0.5, key='_pm')
        st.write(proximity_modifier)
        st.write(state._pm)

still results in the previous issue. Am I doing something wrong?

1reaction
kmcgradycommented, Apr 28, 2021

Thanks for the report @cceyda ! I believe our solution with our implementation of Session State will help on this. I tagged this issue to the project so that when it’s released, we can follow up with a solution!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug - Input cached when not immediately consumed by a State
My rough, high-level understanding is that the Protagonist class stores input from the InputReader and relays it to the State Machine which ...
Read more >
Form Textbox Caching Problem - Stack Overflow
I have a PHP form, with various input fields and textboxes. If you submit and go back, all of the data that was...
Read more >
1747835 - Cache text input type - Bugzilla@Mozilla
Bug 1747835 - P2: Cache text-input-type attribute for text and date/time inputs. r?morgan. 10 months ago. Eitan Isaacson [:eeejay].
Read more >
TurboLinks and caching form inputs · Issue #574 - GitHub
TURBOLINKS BFCACHE: After pressing the back button, users input is NOT cached. The form is reset to it's original default state. Summary. Is ......
Read more >
Thread: Caching problem across jobs with 'Text file Input' step.
Caching problem across jobs with 'Text file Input' step. I am building a URL in a JavaScript step, which returns data in CSV...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found