限制和库变更

本主题介绍当 Streamlit 功能在 Snowflake 中的表现与开源库不同时,所涉及的限制和功能行为变更。

不支持的 Streamlit 功能

在 Streamlit in Snowflake 中不支持以下 Streamlit 功能:

  • st.bokeh_chart (https://docs.streamlit.io/1.39.0/develop/api-reference/charts/st.bokeh_chart)

  • st.set_page_config (https://docs.streamlit.io/1.39.0/develop/api-reference/configuration/st.set_page_config)

    不支持 st.set_page_config 命令的 page_titlepage_iconmenu_items 属性。

  • st.toast (https://docs.streamlit.io/develop/api-reference/status/st.toast)

  • st.balloons (https://docs.streamlit.io/develop/api-reference/status/st.balloons)

  • st.snow (https://docs.streamlit.io/develop/api-reference/status/st.snow)

  • 锚定链接

在 Streamlit in Snowflake 中加载外部资源时的限制

All Streamlit in Snowflake apps run within the Content Security Policy (CSP) (https://content-security-policy.com/) that restricts which resources can be loaded. Snowflake blocks loading code --- including scripts, styles, fonts, and iframe embedding --- from any external domain. However, loading a subset of resources from Mapbox or Carto is supported.

When you use the st.map (https://docs.streamlit.io/develop/api-reference/charts/st.map) or st.pydeck_chart (https://docs.streamlit.io/develop/api-reference/charts/st.pydeck_chart) Streamlit commands in the Streamlit version 1.45.1 or lower, Mapbox provides the map tiles when rendering map content. For Streamlit versions 1.46.1 and higher, Carto is a default provider. Mapbox and Carto are third-party applications and are subject to Snowflake's External Offerings Terms.

重要

Mapbox is not available in the People's Republic of China. Snowflake recommends using Carto instead.

Streamlit in Snowflake 支持从外部域加载图像或媒体,但 Snowflake Native App Framework 不支持。

例如,以下代码运行时没有 Python 错误,但不会在浏览器中加载或执行脚本:

# This will not work
import streamlit.components.v1 as components
components.html("""
<script src="http://www.example.com/example.js"></script>
""", height=0)
Copy

CSP 还会阻止通常被认为不安全的前端调用,例如 eval()

备注

根据 Snowflake 责任共担模式,应用程序开发人员负责安全检查和 Streamlit in Snowflake 应用程序代码的软件供应链。

在 Streamlit in Snowflake 中使用自定义组件时的限制

目前,Streamlit in Snowflake 仅支持不需要调用外部服务的自定义组件。

备注

从第三方来源导入的组件受该组件所附许可证的约束。您有责任确保组件的许可证允许您使用组件。

Snowflake 不会构建或维护您可能导入到 Streamlit in Snowflake 中的第三方组件。使用此类组件的风险自负,不受 Snowflake 的任何担保、服务水平协议或其他类似担保的约束。

其他 Streamlit in Snowflake 限制

Streamlit in Snowflake 有下列额外限制:

Streamlit apps have a limit for displaying data

Streamlit apps running in Streamlit in Snowflake and in Snowflake Native Apps have a 32-MB limit on the size of messages exchanged between the backend and the frontend. If you attempt to display more than 32 MB of data with a single Streamlit command, like st.dataframe, the following error occurs:

MessageSizeError: Data Size exceeds message limit

要避免此限制,请将 Streamlit 应用程序设计为以小于 32 MB 的增量显示数据。对于可运行查询大小或内存中可拥有的数据量,没有明确的限制。

Streamlit in Snowflake 仅支持使用客户端加密的内部暂存区

Streamlit in Snowflake 编辑器不支持从使用服务器端加密的命名暂存区上的文件 创建 STREAMLIT 对象。在这种情况下, Snowsight 会返回错误。

st.cache_datast.cache_resource 尚未得到全面支持

在 Streamlit in Snowflake 中,st.cache_data (https://docs.streamlit.io/library/api-reference/performance/st.cache_data) 和 st.cache_resource (https://docs.streamlit.io/library/api-reference/performance/st.cache_resource) 尚未得到完全支持。缓存仅在单个会话中有效。缓存值不能转移到其他会话,也不能在 Streamlit 应用程序的不同用户之间共享。

st.file_uploader 上传文件的限制为 200 MB

使用 `st.file_uploader<https://docs.streamlit.io/develop/api-reference/widgets/st.file_uploader>`_ 时,您可以上传文件,但每个文件的大小不得超过 200 MB。目前,Streamlit in Snowflake 不支持配此配置。对于较大的文件,可考虑以较小的批次处理数据或使用其他上传方法。

在 Streamlit in Snowflake 中使用查询参数时发生的变更

在 Streamlit in Snowflake 中,对于 st.query_params (https://docs.streamlit.io/develop/api-reference/caching-and-state/st.query_params),URL 中每个查询参数的键都会添加 streamlit- 前缀。使用 st.query_params 获取或设置值时,此前缀不会包含在其中。

例如,请考虑以下 URL:

https://app.snowflake.cn/org/account_name/#/streamlit-apps/DB.SCHEMA.APP_NAME?streamlit-first_key=one&streamlit-second_key=two

该 URL 中的参数可通过 st.query_params 以以下键值对的形式访问:

{
   "first_key" : "one",
   "second_key" : "two"
}
Copy

有关更多信息,请参阅 st.query_params (https://docs.streamlit.io/develop/api-reference/caching-and-state/st.query_params)。

语言: 中文