Refactor figures_to_html to render SVG inline for better display and update initialization logic for dropdown choices in Gradio UI
Browse files
app.py
CHANGED
|
@@ -550,16 +550,22 @@ def make_trend_figs_by_tag(
|
|
| 550 |
|
| 551 |
def figures_to_html(figs_by_tag: Dict[str, go.Figure]) -> str:
|
| 552 |
"""
|
| 553 |
-
各 Figure を
|
| 554 |
-
最初の図だけ PlotlyJS をCDNで同梱し、以降はスリムに。
|
| 555 |
"""
|
|
|
|
|
|
|
| 556 |
parts = []
|
| 557 |
-
first = True
|
| 558 |
for tag, fig in figs_by_tag.items():
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
|
| 564 |
# ======================================
|
| 565 |
# グローバル状態(UI間共有)
|
|
@@ -674,6 +680,10 @@ def render_any(process_name: str, items: List[str], display_mode: str, thr_mode_
|
|
| 674 |
# ======================================
|
| 675 |
# UI
|
| 676 |
# ======================================
|
|
|
|
|
|
|
|
|
|
|
|
|
| 677 |
with gr.Blocks(css="""
|
| 678 |
.gradio-container {overflow: auto !important;}
|
| 679 |
""") as demo:
|
|
@@ -699,10 +709,11 @@ with gr.Blocks(css="""
|
|
| 699 |
label="表示形式"
|
| 700 |
)
|
| 701 |
|
| 702 |
-
status_csv = gr.Markdown()
|
| 703 |
status_thr = gr.Markdown()
|
| 704 |
|
| 705 |
-
process_dd = gr.Dropdown(label="対象プロセス(3行ヘッダーの3行目)",
|
|
|
|
| 706 |
items_cb = gr.CheckboxGroup(label="表示する項目(3行ヘッダーの2行目)", choices=[], value=[])
|
| 707 |
|
| 708 |
with gr.Row():
|
|
@@ -715,11 +726,7 @@ with gr.Blocks(css="""
|
|
| 715 |
html_multi = gr.HTML(label="個別トレンド図(複数枚)", visible=False)
|
| 716 |
|
| 717 |
# コールバック接続
|
| 718 |
-
#
|
| 719 |
-
init_msg, init_proc_update, _ = initialize_default_csv()
|
| 720 |
-
status_csv.value = init_msg
|
| 721 |
-
process_dd.value = init_proc_update.get('value')
|
| 722 |
-
process_dd.choices = init_proc_update.get('choices', [])
|
| 723 |
|
| 724 |
# 2) CSVアップロードで更新
|
| 725 |
csv_uploader.change(
|
|
|
|
| 550 |
|
| 551 |
def figures_to_html(figs_by_tag: Dict[str, go.Figure]) -> str:
|
| 552 |
"""
|
| 553 |
+
各 Figure を SVG に変換してインラインで並べる(<script>不要で確実に表示)。
|
|
|
|
| 554 |
"""
|
| 555 |
+
if not figs_by_tag:
|
| 556 |
+
return "<p>図がありません。</p>"
|
| 557 |
parts = []
|
|
|
|
| 558 |
for tag, fig in figs_by_tag.items():
|
| 559 |
+
# 必要なら width/height/scale を調整可
|
| 560 |
+
svg_bytes = pio.to_image(fig, format="svg", engine="kaleido")
|
| 561 |
+
svg = svg_bytes.decode("utf-8")
|
| 562 |
+
parts.append(
|
| 563 |
+
f'<div style="margin:16px 0;border:1px solid #e5e7eb;border-radius:8px;padding:8px">'
|
| 564 |
+
f'<div style="font-weight:600;margin:4px 0 8px 0;">{tag}</div>'
|
| 565 |
+
f'{svg}'
|
| 566 |
+
f'</div>'
|
| 567 |
+
)
|
| 568 |
+
return "\n".join(parts)
|
| 569 |
|
| 570 |
# ======================================
|
| 571 |
# グローバル状態(UI間共有)
|
|
|
|
| 680 |
# ======================================
|
| 681 |
# UI
|
| 682 |
# ======================================
|
| 683 |
+
init_msg, init_proc_update, _ = initialize_default_csv()
|
| 684 |
+
init_value = init_proc_update.get("value") if isinstance(init_proc_update, dict) else None
|
| 685 |
+
init_choices = init_proc_update.get("choices") if isinstance(init_proc_update, dict) else []
|
| 686 |
+
|
| 687 |
with gr.Blocks(css="""
|
| 688 |
.gradio-container {overflow: auto !important;}
|
| 689 |
""") as demo:
|
|
|
|
| 709 |
label="表示形式"
|
| 710 |
)
|
| 711 |
|
| 712 |
+
status_csv = gr.Markdown(init_msg)
|
| 713 |
status_thr = gr.Markdown()
|
| 714 |
|
| 715 |
+
process_dd = gr.Dropdown(label="対象プロセス(3行ヘッダーの3行目)",
|
| 716 |
+
choices=init_choices, value=init_value)
|
| 717 |
items_cb = gr.CheckboxGroup(label="表示する項目(3行ヘッダーの2行目)", choices=[], value=[])
|
| 718 |
|
| 719 |
with gr.Row():
|
|
|
|
| 726 |
html_multi = gr.HTML(label="個別トレンド図(複数枚)", visible=False)
|
| 727 |
|
| 728 |
# コールバック接続
|
| 729 |
+
# 既定CSVの手動代入は不要(生成時に付与済み)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 730 |
|
| 731 |
# 2) CSVアップロードで更新
|
| 732 |
csv_uploader.change(
|