Urgent help on getting value of input box

Hi @carty,

So, the program you posted has a bunch of issues. Lets look at them one by one.

When the user interacts with the screen in any way, streamlit runs the entire program from the top. So, when the user clicks on"Submit", the code within the if st.button(“submit”) runs and the variables box1 and box3 are initialized to the contents of whatever’s in the st.text_area widget associated with those boxes. However, when the user clicks on the copy button, the code runs from scratch again, and this time, the code associated with submit is not run, and so box1 and box3 are not populated at all. You’ll need to either save those values of box1 and box3 using SessionState semantics described for example in this post: Multi-page app with session state or the one described in https://gist.github.com/FranzDiebold/898396a6be785d9b5ca6f3706ef9b0bc.

The second problem is that you need to collect the input from text_area which has “Generated” as the label and then use that, not use box4.

So, the code would look like this:

import streamlit as st
import clipboard
import session_state
import time

def MAINFUNCTION(tojoin):
    JOINLIST = "\n".join(str(i) for i in tojoin)
    return JOINLIST

state = session_state._get_state()
box2 = st.text_area("enter your age")
labels = [1, 2, 3, 4, 5]
box1 = st.text_area('Generated From function', value='type here')
box4 = st.empty()

if st.button("Submit"):
    runapp = MAINFUNCTION(labels)
    with box4.beta_container():
        state.box4 = st.text_area("Generated", runapp)

    state.box1 = st.text_area("Generated From function", runapp)
    state.box3 = st.text_area('enter your name', runapp)
    # st.success(box1)

if st.button('copy'):
    st.success(f'box1 to be copied: {state.box1}')

  clipboard.copy(state.box1)
  clipboard_paste()
   st.success("copied successfully")

    st.success(f'box4 to be copied: {state.box4}')
    st.success(f'box1 to be copied: {state.box3}')

Let me know if this works for you. The session_state code that I’m importing from is this one: https://gist.github.com/okld/0aba4869ba6fdc8d49132e6974e2e662. I copied the code associated with the class _SessionStateand the routines _get_state and _get_session and saved it as session_state.py.

Dinesh

1 Like