Streamlit components: Org Chart e Hierarchical Grid
Project description
streamlit-rtr-components
Componentes customizados para Streamlit: organograma e grid hierárquico.
Sumário
- Visão geral
- Instalação
- Exemplo rápido
- API
- Formato de dados
- Estrutura do repositório
- Desenvolvimento (Vite + Tailwind v4)
- Build de produção (frontend)
- Empacotamento Python
- Solução de problemas
- Changelog
- Contribuição
- Licença
Visão geral
Dois componentes prontos para uso em Streamlit:
st_orgChart— organograma (árvore hierárquica).st_hierarchicalGrid— grid hierárquico com colunas configuráveis e suporte a imagens (PNG/SVG via data URL).
Stack: Python (Streamlit) + React/TypeScript (Vite) + Tailwind v4.
Artefatos: cada frontend gerafrontend/diste é empacotado junto ao wheel.
Instalação
pip install streamlit-rtr-components
<!-- USAGE: start -->
## Exemplo rápido
import streamlit as st
from rtr_componentes import st_orgChart, st_hierarchicalGrid
st.title("Demo • RTR Components")
st.subheader("Org Chart")
st_orgChart(
data={
"id": "CEO",
"children": [{"id": "CTO"}, {"id": "CFO"}]
}
)
st.subheader("Hierarchical Grid")
data = [
{
"estrutura": "Presidência",
"avatar": "data:image/png;base64,....", # PNG opcional (data URL)
"quantidade_funcionarios": 2167,
"salario_total": "R$ 5.239.551,21",
"salario_medio": "R$ 2.417,88",
"children": [
{
"estrutura": "Assessoria Financeira",
"avatar": "data:image/svg+xml;base64,....", # SVG opcional (data URL)
"quantidade_funcionarios": 1,
"salario_total": "R$ 5.184,00",
"salario_medio": "R$ 5.184,00",
"children": []
}
]
}
]
columns = [
{"label": "Estrutura", "field": "estrutura"},
{"label": "Quantidade Funcionarios", "field": "quantidade_funcionarios"},
{"label": "Salario Total", "field": "salario_total", "secret": True},
{"label": "Salario Medio", "field": "salario_medio"}
]
st_hierarchicalGrid(data=data, columns=columns, expanded=True)
<!-- USAGE: end -->
## API
from rtr_componentes import st_orgChart, st_hierarchicalGrid
st_orgChart(
data: dict | list | None = None,
key: str | None = None,
**kwargs
) -> Any
st_hierarchicalGrid(
data: dict | list | None = None,
columns: list[dict] | None = None,
expanded: bool = False,
key: str | None = None,
**kwargs
) -> Any
# data
# Org: objeto/array hierárquico com id, children, etc.
# Grid: nós com campos livres e children: [].
# columns (Grid): {"label": str, "field": str, "secret"?: bool, "type"?: "text"|"number"|"currency"|...}.
# expanded (Grid): expande nós por padrão.
# Retorno: se o frontend chamar Streamlit.setComponentValue(...), o valor retorna via função Python.
<!-- DATA-FORMAT: start -->
Formato de dados
Imagens: envie como data URL
PNG → data:image/png;base64,<...>
SVG → data:image/svg+xml;base64,<...>
Perfomance: prefira miniaturas (ex.: 64–128 px) para reduzir payload.
Grid: garanta que os nomes em columns[].field existam em cada nó.
<!-- DATA-FORMAT: end -->
## Estrutura do repositório
.
├─ st_orgChart/
│ ├─ __init__.py # wrapper Python (usa frontend/dist)
│ └─ frontend/ # Vite/React/TS
│ ├─ index.html
│ ├─ src/
│ │ ├─ main.tsx
│ │ ├─ StOrgChart.tsx
│ │ └─ index.css # @import "tailwindcss";
│ └─ dist/ # gerado por vite build
├─ st_hierarchicalGrid/
│ ├─ __init__.py
│ └─ frontend/
│ ├─ index.html
│ ├─ src/
│ │ ├─ main.tsx
│ │ ├─ RtrHierarchicalGrid.tsx
│ │ └─ index.css
│ └─ dist/
├─ rtr_componentes/
│ └─ __init__.py # reexporta os dois componentes
├─ pyproject.toml
├─ MANIFEST.in
├─ README.md
└─ LICENSE
## Desenvolvimento (Vite + Tailwind v4)
# Em cada frontend:
npm i
npm run dev
## No seu app Streamlit (dev hot-reload):
# Windows PowerShell
$env:DEV_MODE="true"
$env:FRONTEND_HOST="http://localhost:5173" # altere a porta conforme o componente
streamlit run seu_app.py
# Em dev, o wrapper usa DEV_MODE/FRONTEND_HOST. Em produção (sem envs), ele lê frontend/dist.
<!-- BUILD-FRONTEND: start -->
## Build de produção (frontend)
cd st_orgChart/frontend && npm run build
cd ../../st_hierarchicalGrid/frontend && npm run build
# vite.config.ts (recomendado nos dois):
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tailwind from "@tailwindcss/vite";
export default defineConfig(({ command }) => ({
base: command === "build" ? "./" : "/",
plugins: [react(), tailwind()],
build: { outDir: "dist" }
}));
<!-- BUILD-FRONTEND: end --> <!-- PACKAGING: start -->
## Empacotamento Python
# MANIFEST.in
recursive-include st_orgChart/frontend/dist *
recursive-include st_hierarchicalGrid/frontend/dist *
include README.md
include LICENSE
# pyproject.toml (trechos)
[tool.setuptools]
include-package-data = true
[tool.setuptools.packages.find]
where = ["."]
include = ["st_orgChart*", "st_hierarchicalGrid*", "rtr_componentes*"]
[tool.setuptools.package-data]
"st_orgChart" = ["frontend/dist/**"]
"st_hierarchicalGrid" = ["frontend/dist/**"]
# Build & teste:
python -m build
pip install -e .
<!-- PACKAGING: end --> <!-- TROUBLESHOOT: start -->
# Solução de problemas
# Tela branca/404 em produção → confirme base: "./" no Vite e que frontend/dist existe e foi incluído no wheel.
# RuntimeError: Build não encontrado → rode npm run build em cada frontend antes de instalar.
# Erros de JSX/TS no editor → use TS 5, moduleResolution: "bundler", jsx: "react-jsx", types: ["vite/client"].
# Conflitos NPM (ERESOLVE) → se migrou de CRA, remova react-scripts, apague node_modules/package-lock.json e reinstale.
# Bundle grande (Grid) → faça import dinâmico de html2canvas/jspdf somente na ação de exportar.
# <!-- TROUBLESHOOT: end -->
# Changelog
# <!-- CHANGELOG: start -->
# 1.0.0 — release inicial com st_orgChart e st_hierarchicalGrid.
# <!-- CHANGELOG: end -->
# Contribuição
# Issues e PRs são bem-vindos. Antes de abrir PR:
# Rode npm run build em ambos os frontends.
# Rode npm run lint (se estiver usando ESLint).
# Adicione/atualize exemplos no README quando necessário.
## Licença
# MIT — veja LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file streamlit_rtr_components-1.0.2.tar.gz.
File metadata
- Download URL: streamlit_rtr_components-1.0.2.tar.gz
- Upload date:
- Size: 503.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e766fb61cb9cbe51b0c4e1d7b425a089900719d8d3d5b99fa03e3be2376fb949
|
|
| MD5 |
690540f69a9f8809858e330f3ff7e4bd
|
|
| BLAKE2b-256 |
2f928ddde1038c770ec46097804d34f8491c94faa7aeccb24a5d62555a2ea961
|
Provenance
The following attestation bundles were made for streamlit_rtr_components-1.0.2.tar.gz:
Publisher:
fluxodetrabalho.yml on oliveiraartur/rtr_componentes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
streamlit_rtr_components-1.0.2.tar.gz -
Subject digest:
e766fb61cb9cbe51b0c4e1d7b425a089900719d8d3d5b99fa03e3be2376fb949 - Sigstore transparency entry: 387608846
- Sigstore integration time:
-
Permalink:
oliveiraartur/rtr_componentes@93c7db1d72aeac629bc17a9c674ce66b15c78dc5 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/oliveiraartur
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
fluxodetrabalho.yml@93c7db1d72aeac629bc17a9c674ce66b15c78dc5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file streamlit_rtr_components-1.0.2-py3-none-any.whl.
File metadata
- Download URL: streamlit_rtr_components-1.0.2-py3-none-any.whl
- Upload date:
- Size: 504.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45c1e784ac957a41d0708b772ab1dd35e49f6ec4db6d1724e79b1b574fc22ffb
|
|
| MD5 |
453ac52d13767924eb368c0f8ed67850
|
|
| BLAKE2b-256 |
11a2f78e41ca7461b4e8a29f8951ea578b883449174a7a46629a0e46fc8430db
|
Provenance
The following attestation bundles were made for streamlit_rtr_components-1.0.2-py3-none-any.whl:
Publisher:
fluxodetrabalho.yml on oliveiraartur/rtr_componentes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
streamlit_rtr_components-1.0.2-py3-none-any.whl -
Subject digest:
45c1e784ac957a41d0708b772ab1dd35e49f6ec4db6d1724e79b1b574fc22ffb - Sigstore transparency entry: 387608870
- Sigstore integration time:
-
Permalink:
oliveiraartur/rtr_componentes@93c7db1d72aeac629bc17a9c674ce66b15c78dc5 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/oliveiraartur
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
fluxodetrabalho.yml@93c7db1d72aeac629bc17a9c674ce66b15c78dc5 -
Trigger Event:
release
-
Statement type: