最後活躍 10 months ago

此範例展示如何在 Streamlit 應用中,透過 st.write 和 unsafe_allow_html=True 來顯示自訂物件的 HTML 格式輸出,使物件能夠以自訂的 HTML 樣式呈現。

修訂 61d221fbb2ed5235d7ac1b3b3d069b6638d1fd23

streamlit_custom_object_html.py 原始檔案
1import streamlit as st
2
3class MyObject:
4 def _repr_html_(self):
5 return "<h1 style='color:blue;'>這是一個自訂物件的 HTML 表示</h1>"
6
7obj = MyObject()
8st.write(obj._repr_html_(), unsafe_allow_html=True)
9