Skip to main content

Streamlit components: Org Chart e Hierarchical Grid

Project description

PyPI Python Streamlit License

streamlit-rtr-components

Componentes customizados para Streamlit: organograma e grid hierárquico.

Sumário

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 gera frontend/dist e é 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

streamlit_rtr_components-1.0.3.tar.gz (779.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_rtr_components-1.0.3-py3-none-any.whl (783.2 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_rtr_components-1.0.3.tar.gz.

File metadata

  • Download URL: streamlit_rtr_components-1.0.3.tar.gz
  • Upload date:
  • Size: 779.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for streamlit_rtr_components-1.0.3.tar.gz
Algorithm Hash digest
SHA256 2927a18628ff70231ca8b1e8c8c038d8fa4d32a49a71c3ff3e155d3b7dfd5a07
MD5 cf996b698d4d1bb24fe57ccae436829f
BLAKE2b-256 8910217116ee4290bdd16937698f6fd56358a6b95ade326622db93f6f399b327

See more details on using hashes here.

Provenance

The following attestation bundles were made for streamlit_rtr_components-1.0.3.tar.gz:

Publisher: fluxodetrabalho.yml on oliveiraartur/rtr_componentes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file streamlit_rtr_components-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_rtr_components-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 33178a038f956c3f393ed2aa82fe3cfb141285bc37e9906a82bfdfa400e9b17a
MD5 8f419482be01073e67037a39d5bc5f57
BLAKE2b-256 1b3368b1ce5b0e5116f347a76578f8fb276b0126a3b5b73ddd4fcb3b16bcb6d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for streamlit_rtr_components-1.0.3-py3-none-any.whl:

Publisher: fluxodetrabalho.yml on oliveiraartur/rtr_componentes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page