Note: This sample application has been copied and adapted from its original version here: https://github.com/Snowflake-Labs/streamlit-examples/tree/main/Dynamic%20Filters%20Snowpark
This is a Streamlit demo that showcases how filters can be generated.
The app connects to Snowflake and retrieves the data using snowpark Python, pushing the computations into a Snowflake warehouse.
- Dynamically selectable list of filters ("Select which filters to enable")
- Result preview
- Sankey chart showing the effects of selected filters
- Statement sequence showing which SQL statements are performed to get the result
- Download button to get the csv file with results
To run the app, following steps are required:
localstack
CLI withLOCALSTACK_AUTH_TOKEN
environment variable set- LocalStack Snowflake emulator
- Snowpark for Python
- Streamlit CLI
Note: Snowpark requires python 3.8.*, please ensure that you have that version available in your environment.
The project is using poetry to manage the dependencies and local CI.
To set up the project:
- Install poetry
- Open the project directory in a terminal emulator
- (optional) to force the use of python 3.8, run
poetry env use /path/to/python3.8
- Run
poetry install
to install dependencies into project-specific virtual environment
As an alternative to poetry
, the project can also be set up via pip
:
- Create a python 3.8 virtual environment
- Switch into the created virtual environment
- Use provided
requirements.txt
to install the dependencies:pip -r requirements.txt
To be able to connect to the LocalStack Slowflake emulator when developing locally Streamlit provides a mechanism for storing secrets and connection details in the project (doc link)
To run the sample against LocalStack Snowflake, your local ~/.streamlit/secrets.toml
should look something like this:
[snowpark]
user = "test"
password = "test"
account = "test"
warehouse = "test"
database = "STREAMLIT_DEMO"
schema = "STREAMLIT_USER_PROFILER"
role = "test"
host = "snowflake.localhost.localstack.cloud"
The project comes with a SQL sheet to be run in the environment.
For example, if you have the snow
CLI configured with a localstack
connection profile, the SQL script can be executed as follows:
snow sql -c localstack -f .assets/setup.sql
After performing the setup and switching to the virtual environment, you can run the application using:
streamlit run main.py
This sample application is published under the Apache 2.0 License (see LICENSE
file).