Skip to main content

Gere dashboards visuais como imagens usando HTML/CSS e Playwright.

Project description

Dashgen

📊 Gere dashboards visuais como imagens (PNG) diretamente do Python com HTML, Tailwind CSS e Chart.js.


✨ O que é?

dashgen é um micro-framework que permite criar dashboards dinâmicos e exportá-los como imagens de alta qualidade.

Ideal para gerar relatórios diários, KPIs, resumos visuais e compartilhar automaticamente via e-mail, WhatsApp, sistemas internos etc.


🛠 Instalação

pip install dashgen
playwright install

🚀 Exemplo Completo

from dashgen import Dashboard
from dashgen.core.layout import Row, Column

# Criar o dashboard com altura automática, título estilizado e tema
db = Dashboard(
    title="📊 Relatório de Desempenho Comercial",
    title_style="text-3xl font-bold text-emerald-700",
    logo_path="logo.png",
    size=(1080, None),
    auto_size=True,
    theme={
        "primary": "#0f766e",
        "accent": "#22d3ee",
        "bg": "#f0fdfa",
        "text": "#082f49"
    }
)

# Linha com dois cards
db.add(Row(
    Column(6).add_card("Receita Acumulada", 9000000, 10000000),
    Column(6).add_card("Unidades Vendidas", 430, 500)
))

# Linha com tabela e gráfico de barras
dados = [
    {"Nome": "Projeto A", "Meta": "R$ 3M", "Realizado": "R$ 2.4M", "Variação": "-20%"},
    {"Nome": "Projeto B", "Meta": "R$ 5M", "Realizado": "R$ 5.2M", "Variação": "+4%"}
]

db.add(Row(
    Column(6).add_table("Desempenho por Projeto", dados, ["Nome", "Meta", "Realizado", "Variação"]),
    Column(6).add_chart(
        "bar",
        "Vendas por Mês",
        [
            {"label": "Jan", "value": 120},
            {"label": "Fev", "value": 135},
            {"label": "Mar", "value": 160},
            {"label": "Abr", "value": 110},
            {"label": "Mai", "value": 190}
        ],
        options={
            "height": 300,
            "show_data_labels": True,
            "show_legend": False,
            "show_x_axis": True,
            "show_y_axis": True,
            "autosize_x": True,
            "bar_color": "#0f766e"
        }
    )
))

# Linha com gráfico de linha (largura total)
db.add(Row(
    Column(12).add_chart(
        "line",
        "Receita Total (R$)",
        [
            {"label": "Jan", "value": 1200000},
            {"label": "Fev", "value": 1450000},
            {"label": "Mar", "value": 1600000},
            {"label": "Abr", "value": 1800000},
            {"label": "Mai", "value": 2100000}
        ],
        options={
            "height": 460,
            "show_legend": False,
            "show_x_axis": True,
            "show_y_axis": True,
            "autosize_x": True,
            "tension": 0.4,
            "fill": False,
            "border_color": "#22d3ee"
        }
    )
))

# Gerar imagem
db.generate("output_dashboard.png")
print("✅ Dashboard gerado com sucesso!")

🧱 Componentes Disponíveis

📐 Layout

  • Row(...): Agrupa colunas
  • Column(width=...): Define largura (1 a 12)

📦 Card (KPI)

Column(6).add_card("Título", valor, meta, style={ ... })

Suporta personalização com:

  • title_color, title_size, text_size
  • bar_color, card_class

📊 Tabela

Column(6).add_table("Título", data, headers)
  • data: lista de dicionários
  • headers: nomes das colunas a exibir

📈 Gráfico (Chart.js)

Column(6).add_chart("bar" ou "line", "Título", data, options={...})
  • data: lista com label e value

  • options:

    • height: altura do canvas
    • fill: preencher área sob a linha
    • tension: suavidade das curvas
    • autosize_x / autosize_y: expandir horizontal/vertical
    • show_legend: mostrar legenda
    • show_x_axis / show_y_axis: mostrar eixos
    • show_data_labels: mostrar valores sobre as barras

🎨 Tema Personalizado

theme = {
    "primary": "#005f73",  # Barras e títulos
    "accent": "#94d2bd",   # Detalhes
    "bg": "#fefae0",       # Fundo da imagem
    "text": "#001219"      # Cor do texto
}

🧠 Funcionalidades Especiais

  • auto_size=True: ajusta altura da imagem com base no conteúdo
  • Responsivo com Tailwind
  • Gráficos com Chart.js
  • Rótulos de valores (chartjs-plugin-datalabels)
  • Estilização por componente (style, options)

📚 API Referência

📘 Dashboard(...)

Parâmetro Tipo Descrição
title str Título do dashboard
logo_path str (opcional) Caminho da logo
size (int, int) Tamanho fixo da imagem
auto_size bool Ajuste automático de altura
theme dict Cores do tema

✅ Requisitos

  • Python 3.7+
  • playwright
  • jinja2
pip install dashgen
playwright install

🖼 Gere imagens de dashboards com visual moderno, responsivo e exportável – em uma linha de código.

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

dashgen-0.2.3.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

dashgen-0.2.3-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file dashgen-0.2.3.tar.gz.

File metadata

  • Download URL: dashgen-0.2.3.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for dashgen-0.2.3.tar.gz
Algorithm Hash digest
SHA256 ff32c7cc104c5d5c4d151186047dde95c5f6de9d0c5df09c0ce9c6fa6c54f2ab
MD5 6e1a1f4e7d380b2a779b5c8547aef1b6
BLAKE2b-256 1a55d81583e2d6b2260a27d77273c5b61f41d717ca46aee5a688536f9d81b784

See more details on using hashes here.

File details

Details for the file dashgen-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: dashgen-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for dashgen-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0dc2e86d8bfe243018e0c90728fa0683b6bd40b86b06d8af276a4855b5bfa51f
MD5 4bd3dff45ecbe823843ea6d903fab133
BLAKE2b-256 0fe64923349fa0cb5ad84c25afa37c36bbce9a36ff687c0648b071fdd2a52cc5

See more details on using hashes here.

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