Streamlit条件树构建器
项目描述
查看实时演示 !
该组件允许用户构建复杂的条件树,可用于过滤数据框或构建查询。
安装
pip install streamlit-condition-tree
功能
- 高度可配置
- 字段可以是以下类型
- 简单(字符串、数字、布尔值、日期/时间/日期时间、列表)
- 结构(将作为树显示在选择框中)
- 比较运算符可以是
- 二元(== != < > ..)
- 一元(为空、为空值)
- 'between'(用于数字、日期、时间)
- 复杂的运算符,如'proximity'(接近)
- 右侧可以是
- 值
- 另一个字段(同一类型)
- 函数(参数也可以是值/字段/函数)
- 左侧可以是字段或函数
- 支持规则和规则组的重新排序(拖放)
- 导出到MongoDb、SQL、JsonLogic、SpEL或ElasticSearch
基本用法
过滤数据框
import pandas as pd
from streamlit_condition_tree import condition_tree, config_from_dataframe
# Initial dataframe
df = pd.DataFrame({
'First Name': ['Georges', 'Alfred'],
'Age': [45, 98],
'Favorite Color': ['Green', 'Red'],
'Like Tomatoes': [True, False]
})
# Basic field configuration from dataframe
config = config_from_dataframe(df)
# Condition tree
query_string = condition_tree(config)
# Filtered dataframe
df = df.query(query_string)
构建查询
import streamlit as st
from streamlit_condition_tree import condition_tree
# Build a custom configuration
config = {
'fields': {
'name': {
'label': 'Name',
'type': 'text',
},
'qty': {
'label': 'Age',
'type': 'number',
'fieldSettings': {
'min': 0
},
},
'like_tomatoes': {
'label': 'Likes tomatoes',
'type': 'boolean',
}
}
}
# Condition tree
return_val = condition_tree(
config,
return_type='sql'
)
# Generated SQL
st.write(return_val)
API
参数
def condition_tree(
config: dict,
return_type: str,
tree: dict,
min_height: int,
placeholder: str,
key: str
)
- config: Python字典(主要用于定义字段),类似于React组件的JSON副本。
可以通过config_from_dataframe
从DataFrame构建基本配置。
对于更高级的配置,请参阅组件文档和演示。
注意:JavaScript函数(例如:验证器)尚不支持。
-
return_type: 返回值的格式
- queryString
- mongodb
- sql
- spel
- elasticSearch
- jsonLogic
默认: queryString(可用于使用DataFrame.query过滤pandas DataFrame)
-
tree: 输入条件树(见下文部分)
默认: None
-
min_height: 组件框架的最小高度
默认: 400
-
placeholder: 条件树为空时显示的文本
默认: None
-
key:如果要随时间改变其参数而不重新创建,则固定身份。
还可以用于访问生成的条件树(见下文章节)。默认: None
导出和导入条件树
当为组件定义键时,生成的条件树可以通过st.session_state[key]
作为字典访问。
可以通过tree
参数将其作为输入树加载。
潜在的未来改进
- JavaScript支持:允许在配置中注入JavaScript代码(例如,验证器)
项目详情
关闭
streamlit-condition-tree-jb-0.1.2.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | be1eda9b8892d274f1d6fc960187bcf78dd4d0eb4781204aa820c32aa2798471 |
|
MD5 | cfd623c2c167ba869d0f6fd144577802 |
|
BLAKE2b-256 | c585485d72f896d37315d00c6571ad4bed3e85981cb3f418468dbe724676f449 |
关闭
streamlit_condition_tree_jb-0.1.2-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | e012b69d62f9754fb526a57fdf88abc3a5a35ef661d03663d4955ed0c9cb8890 |
|
MD5 | 703b19aeb25f4d4478f68f1d54282fc7 |
|
BLAKE2b-256 | 6d3ac7feb2e063e3a734dfc189dce910ce3f5163541cd45c635525a646904b69 |