liveBook · Manning

Streamlit component

As explained in DuckDB in Action

A Streamlit component is an encapsulated interface element that can be parameterized in Python and rendered as part of a Streamlit web page.

A Streamlit component is an encapsulated interface element declared and parameterized in Python, while Streamlit renders the required web-page pieces. This avoids writing individual HTML fragments and JavaScript for client-side interactivity. section 9.1.3

Player search workflow

Install streamlit-searchbox, import st_searchbox, and place two parameterized search boxes in columns. Each box calls search_players when its value changes, supports autocomplete, and returns the selected player. The selections can drive a database query and display match history in a DataFrame. section 9.1.3

Listing 9.3 Parameterizing a Streamlit component with Python
left, right = st.columns(2)  #1
with left:
    player1 = st_searchbox(search_players,  #2
        label="Player 1",
        key="player1_search",
        default="Roger Federer",
        placeholder="Roger Federer"
    )
with right:
    player2 = st_searchbox(search_players,
        label="Player 2",
        key="player2_search",
        default="Rafael Nadal",
        placeholder="Rafael Nadal"
    )

Shows two searchbox components configured with Python callbacks, labels, keys, defaults, placeholders, and column layout. section 9.1.3

How DuckDB in Action covers it

How deep it goes
Explains declaration, Python parameterization, callbacks, layout, defaults, and returned selections, stopping at component internals.
Examples
Demonstrates player search for Roger Federer, Rafael Nadal, and Andy Murray, followed by queried match results.
What you can do after
Apply it via streamlit-searchbox to build parameterized search controls and connect selections to interactive results.
How it connects
Connects Streamlit components with Python, HTML, JavaScript, autocomplete, columns, database queries, and DataFrames.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of DuckDB in Action. The section links point to the parts of the book it draws on.