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.5.tar.gz (782.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.5-py3-none-any.whl (786.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: streamlit_rtr_components-1.0.5.tar.gz
  • Upload date:
  • Size: 782.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.5.tar.gz
Algorithm Hash digest
SHA256 b353a7548c060385123fbc05496af300b81dd30340440fa9860639e9c514bdc1
MD5 294f8cfe6de17aa365e7feced515af95
BLAKE2b-256 f8920b529e8f7f9c4447ef35f4bf953b2574ab0a777237225e91963ae4bc8f0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for streamlit_rtr_components-1.0.5.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.5-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_rtr_components-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 dba13afe6df009a63f05a2625bea34a5c7361bf2743b6681ffc5f1ba3760db88
MD5 2579640e00c14fd2a93ab99556916a5b
BLAKE2b-256 f313286623d1c36ae7c62ee9a1b9d476d17e077a1db38ab0493a746a97830f99

See more details on using hashes here.

Provenance

The following attestation bundles were made for streamlit_rtr_components-1.0.5-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