DaXin Space

DaXin Space


Clicking the button in Python Streamlit adds an input box.

Streamlit is a Python-based WebUI tool, and it is not an exaggeration to say that it is a low-code tool. I used it to create a page for myself these days and generated a rule file in YAML format. I encountered a situation where interaction was needed in the middle, such as clicking a button to add an input box. After searching for a long time, I finally found the approach and code written by a foreign guy, and both the idea and the code are very good, so I recorded it here.

import streamlit as st
import random
import string

if 'input_keys' not in st.session_state:
    st.session_state.input_keys= []

if st.button("Add new row"):

input_values = []
for input_key in st.session_state.input_keys:
    input_value = st.text_input("Please input something", key=input_key)


Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.