timmy / Streamlit 顯示自訂物件的 HTML 表示
0 Favoriten
0 Forks
1 Dateien
Zuletzt aktiv 10 months ago
此範例展示如何在 Streamlit 應用中,透過 st.write 和 unsafe_allow_html=True 來顯示自訂物件的 HTML 格式輸出,使物件能夠以自訂的 HTML 樣式呈現。
| 1 | import streamlit as st |
| 2 | |
| 3 | class MyObject: |
| 4 | def _repr_html_(self): |
| 5 | return "<h1 style='color:blue;'>這是一個自訂物件的 HTML 表示</h1>" |
| 6 | |
| 7 | obj = MyObject() |
| 8 | st.write(obj._repr_html_(), unsafe_allow_html=True) |
Neuer
Älter