Combinig user input with slider and multi select

I have split the code into Two parts. Thanks to some help yesterday, I’ve been able to use Part one of the code on stream lit to combine sliders and multiselect when filtering my data frame.

This all works fine.

I’ve written the code in part 2 today for users to search for a Horse, Trainer, or Jockey from the df.

The problem is that each search will open a new df in streamlit.

Is there a way to add the search results (part 2) to the (Part 1)

The end goal is to show One df using filters with the slider, Multiselect, and user search.


#Part One

import streamlit as st    
import pandas as pd    

df = pd.DataFrame({
    "Horse": ["Horse 1", "Horse 2", "Horse 3", "Horse 4", "Horse 5"],     
    "RDB_Rating": [230, 186, 255, 450, 171],    
    "Country": ["UK", "Colombia", "Egypt", "Brazil", "Japan"]    
    "Jockey": ["Ap Mcoy", "R Walsh", "D Jacob", "W Carson", "R Blackmore"]     
    "Trainer":["Mullins". "Elliott", "Dixon", "Healy", "Newland"] }    
Country = st.sidebar.multiselect(    
    "Select a Country",    
RDB_Rating = st.sidebar.slider("Select a rating range", 0, 300, (0, 300))    
if Country:     
    df = df[df["Country"].isin(Country)]    
if RDB_Rating:    
    df = df[df["RDB_Rating"].between(RDB_Rating[0], RDB_Rating[1])]     
#Part Two    

text_search = st.text_input("Search Horse", value="")    
m1 = df["Horse"].str.contains(text_search)    
df_search = df[m1]    
if text_search:    
text_search = st.text_input("Search for Jockey", value="")     
m2 = df["Jockey"].str.contains(text_search)     
df_search = df[m2]      
if text_search:      
text_search = st.text_input("Search for Trainer", value="")     
m3 = df["Trainer"].str.contains(text_search)       
df_search = df[m3]       
if text_search:      


Hi @liam_healy

There’s a blog Auto-generate a dataframe filtering UI in Streamlit with filter_dataframe! that shows how to create a dataframe filtering UI which may provide some ideas as well as code snippets that you can use.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.