how to show suggestions in st.text_input if we want to inport any value from dataframe.
for example if i have a dataframe which consist of fruit names and their colour. the first column is name of the fruit and second column is colour.
what i want to do is give name as st.text)input it shows suggestion as drop down box and then after choosing the name it shows me the corresponding color.
please help!!!
i know it is basic. sorry.
No need to ever apologize on something being basic - we are all beginners at some point! In this case I think you can just use st.selectbox to do what you want; st.selectbox allows you to type in the box or to choose from a suggested drop down. Hereās some sample code of how you could use that. If just put your cursor in the box it will show you all of the dropdown items, but if you start typing āstrā it will filter down to suggest āstrawberry and if you type in āappleā it will say āno resultsā:
fruit = pd.DataFrame({
'name': ['strawberry', 'pear', 'banana'],
'colour': ['red', 'green', 'yellow']
})
selected_fruit = st.selectbox('Select a fruit', fruit['name'])
selected_colour = fruit[fruit.name == selected_fruit].iloc[0].loc['colour']
'The colour of a ', selected_fruit, ' is ', selected_colour
Let me know if that fixes your issue!
Hi @Shubham_Rathore. Great question. Thanks for asking.
okay, i will remember that and yeah thank you, it worked.