Getting error while using select box with form

Here is my code

with st.form("my_form"):

	keyword = st.text_input("Type Stock name(without spaces)")
	url = 'https://www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords='+keyword+'&apikey='+key+'&datatype=csv'


	suggestions = pd.read_csv(url)

	sn_dict = [[name, region, symbol] for name, region, symbol in zip(suggestions.name, suggestions.region)]

	selected_stock_symbol = st.selectbox('Select the desired one', sn_dict)[2]


	submitted = st.form_submit_button("Submit")
	if submitted:
		st.write(selected_stock_symbol)

and I am getting the following error

Hey Rajat,

One of the constraints of forms is that they cannot have interdependent widgets, such as the output of widget1 cannot be the input to widget2 inside a form, which seems to be the case in your code. (see documentation)
With st.button it will be like the following:

import streamlit as st
import pandas as pd

key = '#'
keyword = st.text_input("Type Stock name (without spaces)")
if keyword:
    url = 'https://www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords='+str(keyword)+'&apikey='+str(key)+'&datatype=csv'
    suggestions = pd.read_csv(url)
    sn_dict = [[name, region, symbol] for name, region, symbol in zip(suggestions.name, suggestions.region, suggestions.symbol)]
    selected_stock_symbol = st.selectbox('Select the desired one', sn_dict)[2]
    
    # if selected_stock_symbol:
    if st.button("Selected stock symbol"):
        st.write(selected_stock_symbol)
1 Like

Thank you very much @nainiayoub, It is working now :+1: :+1: :+1: