Add front-end experience to an app using Streamlit¶
This topic describes how to include a Streamlit app within a Snowflake Native App.
About Streamlit and the Snowflake Native App Framework¶
Streamlit is an open-source Python library that makes it easy to create and share custom web apps for machine learning and data science. By using Streamlit you can quickly build and deploy powerful data applications.
For information about the open-source library, see the Streamlit Library documentation.
Within the Snowflake Native App Framework you can use Streamlit to perform the following:
Create a front-end web app that enables consumers to visualize the data provided by your Snowflake Native App.
Create a user interface that allows consumers to grant privileges and create references to objects within their account that are used by the Snowflake Native App.
See Request access to objects in a consumer account for more information.
See Unsupported Streamlit Features for information on unsupported Streamlit features.
Supported versions of the Streamlit library¶
The Snowflake Native App Framework supports v1.22.0 of the Streamlit library. Support for later versions of the Streamlit library will be included as they are released.
Supported external packages¶
By default, a Streamlit app that is included within a Snowflake Native App includes the
snowflake-snowpark-python packages pre-installed in the consumer environment. The consumer environment
also has access to the dependencies required by these packages.
Unsupported Streamlit Features¶
The following Streamlit features are not currently supported when using Streamlit in a Snowflake Native App:
Custom components are not supported.
page_iconproperties of the st.set_page_config command are not supported.
Custom Components, including:
The following experimental features:
Unsafe HTML using
unsafe_allow_html=Trueis not supported in st.markdown.
Network access via the internet
Workflow for creating and testing a Streamlit app¶
The following workflow describes a typical workflow for including a Streamlit app in an application package. Depending on the requirements of your app, this may be an iterative process.
Develop your native app.
This includes adding the data content that you want consumers to access using Streamlit. See Snowflake Native App Framework workflow for more information.
Review the following sections to understand the supported version of the Streamlit library and unsupported features:
Develop a Streamlit app.
See the Streamlit Library documentation for information on using the Streamlit open-source library.
Create a local directory structure for the Streamlit app.
See Example directory structure for a Streamlit app for recommendations on how organize your Streamlit files within the structure of you app.
Add an entry for the Streamlit app to the
To include a Streamlit app, you must include the name of the default Streamlit file in the
manifest.ymlfile. See Adding a Streamlit app to the manifest file for more information.
Add a CREATE STREAMLIT statement to the setup script.
When running the CREATE APPLICATION command, the setup script runs the CREATE STREAMLIT statement to create a Streamlit object. This object contains the schema and Python files required by the Streamlit app.
environment.ymlfile to include additional libraries in your Streamlit app.
See Add additional packages to a Streamlit app for more information.
Upload the Streamlit files,
environment.ymlfile, setup script and
manifest.ymlfiles to a named stage. To include Streamlit code files in an application package, the files must be uploaded to a named stage.
Test the application package.
After creating the files required by the application package and Streamlit app, create an application object to test the setup script and
See Test the application package containing the Streamlit app for more information.
View the Streamlit app in Snowsight.
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:
Note that the directory structure you create depends on the requirements of your app and development environment.
environment.yml file must be at the same level as your main file of your Streamlit app.
See Reference 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
extension_code: true entry is required to enable any extension code in your app.
default_streamlit: app_schema.streamlit_app_na entry specifies the location of the
schema containing your Streamlit app.
Create the Streamlit object in the setup script¶
The following example shows how to use CREATE STREAMLIT within the setup script of an app.
CREATE OR REPLACE STREAMLIT app_schema.my_test_app_na
MAIN_FILE = '/streamlit_app.py';
GRANT USAGE ON SCHEMA APP_SCHEMA TO APPLICATION ROLE app_public;
GRANT USAGE ON STREAMLIT APP_SCHEMA.MY_TEST_APP_NA TO APPLICATION ROLE app_public;
This example creates a Streamlit object within a schema named
The CREATE STREAMLIT command uses the Streamlit app specified by the
MAIN_FILE clause. The directory location is specified by the value of the FROM clause.
See Example directory structure for a Streamlit app for information on creating the directory structure for a Streamlit app within an application package.
This example also grants the required privileges on the schema and Streamlit object to an application role.
Add additional packages to a Streamlit app¶
environment.yml file to add additional Python packages to a Streamlit app. For
example, to add the
scikit-learn library to a Streamlit app, add the following to the
channels properties are both required.
- snowflake key is required under the
channels property. This indicates the
Snowflake Anaconda Channel.
You can only install packages listed in the Snowflake Anaconda Channel. Snowflake does not support external Anaconda channels in Streamlit.
Test the application package containing the Streamlit app¶
To test the application package containing the Streamlit app, create an application object using the files on a named stage by running the CREATE APPLICATION as shown in the following example:
CREATE APPLICATION hello_snowflake_app FROM APPLICATION PACKAGE hello_snowflake_package USING '@hello_snowflake_code.core.hello_snowflake_stage';
Depending on what you need to test, you can create the application object using other forms of the CREATE APPLICATION. For example, you may want to test the Streamlit app as part of a version or upgrade. See Create an application object.
Test the Streamlit app in Snowsight¶
To test the Streamlit app, view the app in Snowsight by doing the following:
Sign in to Snowsight.
In the left navigation bar, select Streamlit.
Select the Streamlit app you want to view.
The main Streamlit app opens in the Snowsight.
Optional: If you are viewing a multi-page Streamlit app, select a tab to view additional pages.
Troubleshoot a Streamlit app in the Snowflake Native App Framework¶
If the app displays an unknown error, make sure you have tried the solutions described in the following sections.
Acknowledge the Terms of Service¶
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.