Adding a Streamlit App to an Application Package

This topic describes how to add a Streamlit app to an application package. .

About Using Streamlit in an Application

Streamlit is an open source Python framework for developing data science and machine learning applications. The Snowflake Native App Framework allows you to include Streamlit apps in a Snowflake Native App to provide user interaction and data visualization.

Note

See Unsupported Streamlit Features and Limitations When Using Streamlit in the Native App Framework for information on unsupported Streamlit features.

Example Directory Structure for a Streamlit App

Like other Python modules, to add a Streamlit app to an application package you must upload your Streamlit code files to a named stage. See PUT for information on how to upload files to a stage.

To account for multiple versions of a Snowflake Native App, consider using a directory structure similar to the following to maintain your Streamlit apps and related application files:

@test.schema1.stage1:
└── /
    ├── manifest.yml
    ├── readme.md
    ├── scripts/setup_script.sql
    └── code_artifacts/
        └── streamlit/
            └── environment.yml
            └── streamlit_app.py
Copy

Note that the directory structure you use depends on your environment.

Note

The environment.yml file must be at the same level as your main file of your Streamlit app.

See Referencing External Code Files for more information on relative paths.

Adding a Streamlit App to the Manifest File

To include a Streamlit file in an application package, add the following entries in the manifest.yml file.

artifacts:
  ...
  extension_code: true
  ...
Copy

The extension_code: true entry is required to enable any extension code in your app.

configuration:
  ...
  default_streamlit: app_schema.streamlit_app_na
  ...
Copy

The default_streamlit: app_schema.streamlit_app_na entry specifies the location of the schema containing your Streamlit app.

Adding a Streamlit App to the Setup Script

The following example shows how to use CREATE STREAMLIT within the setup script.

CREATE STREAMLIT app_schema.my_test_app_na
     FROM '/code_artifacts/streamlit'
     MAIN_FILE = '/streamlit_app.py';

GRANT USAGE ON SCHEMA APP_SCHEMA TO DATABASE ROLE app_public;
GRANT USAGE ON STREAMLIT APP_SCHEMA.MY_TEST_APP_NA TO DATABASE ROLE app_public;
Copy

This example creates a Streamlit object within a schema named app_schema. The CREATE STREAMLIT command uses the Streamlit app specified in the MAIN_FILE clause within the directory specified by the FROM clause.

Unsupported Streamlit Features

The following Streamlit features are not currently supported:

Limitations When Using Streamlit in the Native App Framework

This section describes limitations when using Streamlit in the Snowflake Native App Framework.

Custom Components Are Not Supported

Custom components are not supported.

Integrated Version Control or CI/CD Systems Are Not Supported

Streamlit apps are not integrated with version control systems. App history or code changes are permanent and cannot be rolled back.

There is no integration with GitHub, GitLab, or other version control vendors.

App Edits are Viewable by App Viewers

When a developer runs the app while editing, the changes become live immediately to app viewers.

The Seaborn and Matlibplot Libraries are Not Supported

The Seaborn and Matlibplot libraries are not supported. Both have dependencies on the st.image() function which is currently not supported.

Troubleshooting Streamlit

If the app displays an unknown error, make sure you have tried the solutions described in the following sections.

Acknowledging the Terms of Service

To use Streamlit and the packages provided by Anaconda in Snowflake, you must acknowledge the Snowflake Third Party Terms. To learn more, see Using Third-Party Packages from Anaconda.

Firewall Allowlisting

Each Streamlit app uses a unique subdomain. If you use strict firewalls, add *.snowflake.app to your firewall allowlist. Adding this entry to your allowlist, allows your apps to communicate with Snowflake servers without any restrictions.