File size: 1,150 Bytes
3ab32c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import pandas as pd


def df_to_html_table(df: pd.DataFrame, title: str) -> str:
    if df is None or df.empty:
        return f"<div class='tbl'><h4>{title}</h4><em>Empty table</em></div>"
    return f"""
    <div class='tbl'>
      <h4>{title}</h4>
      {df.to_html(index=False, escape=False)}
    </div>
    """


def style_block() -> str:
    return """
    <style>
      .tbl { margin: 1rem 0; padding: 0.5rem 0.75rem; background: var(--block-background-fill); border-radius: 12px; color: var(--body-text-color); }
      .tbl h4 { margin: 0.25rem 0 0.75rem; font-weight: 600; color: var(--body-text-color); }
      .tbl table { border-collapse: collapse; width: 100%; font-size: 14px; color: var(--body-text-color); }
      .tbl th, .tbl td { border: 1px solid var(--border-color-primary); padding: 8px; vertical-align: top; }
      .tbl tr:nth-child(even) { background-color: var(--background-fill-secondary); }
      .tbl th { background-color: var(--background-fill-primary); text-align: left; color: var(--body-text-color); }
      .meta { font-size: 12px; color: var(--body-text-color-subdued); margin-top: 0.25rem; }
    </style>
    """