m-wrzr / streamlit-searchbox

Streamlit searchbox that dynamically updates and provides a list of suggestions based on a provided function
MIT License
203 stars 26 forks source link

Set initial search or initial list of items #21

Closed hoggatt closed 9 months ago

hoggatt commented 9 months ago

Hi, there are cases where someone will just click on the box and I want to show all possible items. Right now, the search function isn't called until the user types something. Can there be an option to call the search function on click (or simply give it a list of items to show by default?).

hoggatt commented 9 months ago

It would also be nice if there was an option to disable 'st.experimental_rerun()'. This can mess things up sometimes depending on the app. Just returning the value might be good enough. Alternatively, have it only do a rerun when 'enter' is pressed.

m-wrzr commented 9 months ago

Thanks for the suggestions! I've added a rerun_on_update option to disable rerunning and a default_options list similar to the selection defaults, which can provide an option list before the first suggestion.

hoggatt commented 9 months ago

Thanks so much! One quick thing, I think you forgot the update the doc for the st_searchbox here.

There are two other functions I think could be helpful for people (although I don't personally need them so I won't make a new issue):

  1. Allow specifying a reset_function (along with the search_function). Then when the box is cleared, something in the streamlit app can be run. This can be useful if you want to prevent certain things from happening if the searchbox is reset.
  2. Allow specifying a 'blank search value". When the box is blank (ie newly created or reset): run a search. This is similar to setting the default list (what you just implemented), but it would re-run the search each time it is cleared so it's up-do-date. Since streamlit re-runs a lot, this one might not be as helpful.