创建 Streamlit 应用程序¶
先决条件
Before creating a Streamlit app with Snowflake CLI, you should meet the following prerequisites:
- Ensure that your account has the correct privileges as described in Privileges required to create and use a Streamlit app.
- 确保可以创建或访问您能在其中上传 Streamlit 应用程序文件的命名暂存区。
引导 Streamlit 应用程序¶
The snow init command creates a local directory with a sample set of files that help you get started creating a Streamlit app. When you execute this command, Snowflake CLI creates the following directory structure:
要初始化 Streamlit 应用程序,请输入以下命令:
Caution
Files inside a project directory are processed by Snowflake CLI and could be uploaded to Snowflake when executing other snow streamlit commands. You should use caution when putting any sensitive information inside files in a project directory.
For more information about the file structure, see Organize your Streamlit app files.
为 Streamlit 应用程序创建项目定义¶
Each Streamlit app in Snowflake must include a snowflake.yml project definition file. Streamlit is limited to one application per project definition file.
The following shows a sample snowflake.yml project definition file:
下表描述了 Streamlit 项目定义的属性。
Streamlit project definition properties
| Property | Definition |
|---|---|
identifier optional、string | 实体的可选 Snowflake 标识符。该值可以采用以下形式:
Both unquoted and quoted identifiers are supported. To use quoted identifiers, include the surrounding quotes in the YAML value (e.g.
Note An error occurs if you specify a |
type optional、string | Must be streamlit. |
comment optional、string | Comment for the Streamlit dashboard. |
title optional、string | Human-readable title for the Streamlit dashboard. |
stage optional、string | Stage in which the app’s artifacts will be stored. Default: None. |
query_warehouse required、string | Snowflake warehouse to host the app. |
main_file optional、string | Entrypoint file (https://docs.streamlit.io/get-started/tutorials/create-an-app) of the streamlit app. Default: “streamlit_app.py”. |
pages_dir optional、string | Streamlit pages (https://docs.streamlit.io/get-started/tutorials/create-a-multipage-app). Default: “pages”. |
external_access_integrations optional、string sequence | Names of external access integrations needed for this Streamlit application code to access external networks. See the optional parameters for CREATE STREAMLIT for more details. |
secrets optional、dictionary | 将密钥的名称分配给变量,以便在从应用程序代码中的密钥中检索信息时,可以使用这些变量引用密钥。 |
imports optional、string sequence | Stage and path to previously uploaded files you want to import. See the optional parameters for CREATE STREAMLIT for more details. |
artifacts required、string sequence | 要添加到部署根的文件源和目标对的列表。您可以使用以下工件属性:
Destination paths that reference directories must end with a You can also pass in a string for each item instead of a If You can also pass in a string for each item instead of a |
grants optional, grant sequence | Grants that should be given for the Streamlit app. Each grant must specify the privilege and target role. For more details, see the optional parameters for CREATE STREAMLIT. |