This example accompanies the documentation page for Streamlit integration.
Streamlit is an open-source Python library to create web applications with minimal effort. It's an effective solution to create simple dashboards, interactive data visualizations, and proof-of-concepts for data science, machine learning, and LLM applications.
In this example, We will build a simple financial dashboard based on the Kaggle Bank Marketing Dataset.
python -m venv ./venv. venv/bin/activate (or source venv/bin/Scripts on Windows)pip install -r requirements.txtstreamlit run app.pyAdding Hamilton to your Streamlit application can provide a better separation between the dataflow and the UI logic. They pair nicely together because Hamilton is also stateless. Once defined, each call to Driver.execute() is independent. Therefore, on each Streamlit rerun, you use Driver.execute() to complete computations. Using Hamilton this way allows you to write your dataflow into Python modules and outside of the Streamlit.
Hamilton transformations are defined in the module logic.py. This includes downloading the data from the web, getting unique values for job, conducting groupby aggregates, and creating plotly figures.
The Streamlit UI is defined in app.py. Notice a few things:
app.py doesn't have to depend on pandas and plotly.@cache_resource allows to create the Driver only once.@cache_data on _execute() will automatically cache any Hamilton result based on the combination of arguments (final_vars, inputs, and overrides)get_state_inputs() and get_state_overrides() will collect values from user inputs.execute() parses the inputs and overrides from the state and call _execute().app.py and logic.py makes it easier to add data transformations or extend UI, and debug errors associated with either.logic.py can be reused elsewhere with Hamilton.