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.1.tar.gz (503.7 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.1-py3-none-any.whl (504.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: streamlit_rtr_components-1.0.1.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

Hashes for streamlit_rtr_components-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d20be6ad49c61f90bbac440379a08b7b890e33a61fd7443495fcad2f7376d197
MD5 34b685bca05fd58c207b22bfb0d4ce87
BLAKE2b-256 65dba032f6c729a280e3dc8cf362f3727287b76e3fb12df7d2916745418a8c92

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for streamlit_rtr_components-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 47a9180c9e589a90911191503e3bd8afc90908067d7ba92164c1563100e29b6e
MD5 6fe87d39db78a4641b1f15856c6644d2
BLAKE2b-256 7e02c73cdecd80f444886e7359701c0a39e3adab13a060900324658ca2452e9d

See more details on using hashes here.

Provenance

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