timmy / Streamlit 整合 Lit Web Component

0 polubień
0 forków
1 plików
Ostatnio aktywne 10 months ago
此範例展示如何在 Streamlit 應用中嵌入 Lit Web Component,而不依賴 CDN。使用 Web Components 技術,可封裝自訂 UI 元件,並透過 JavaScript 互動,適用於建立模組化的前端元件,提升 Web 應用的可維護性與重用性。
1 import streamlit as st
2 import streamlit.components.v1 as components
3
4 st.title("使用 Lit Web Component (無 CDN)")
5
6 lit_component = """
7 <script type="module">
8 class MyLitComponent extends HTMLElement {
9 constructor() {
10 super();

timmy / Streamlit 顯示自訂物件的 HTML 表示

0 polubień
0 forków
1 plików
Ostatnio aktywne 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)

timmy / Streamlit 超連結

0 polubień
0 forków
1 plików
Ostatnio aktywne 10 months ago
此範例展示如何在 Streamlit 應用中使用 st.markdown 搭配 unsafe_allow_html=True 來插入 HTML 連結,使使用者能夠點擊超連結並在新視窗開啟指定網站。
1 import streamlit as st
2
3 st.markdown(
4 '<a href="https://www.example.com" target="_blank">點擊這裡瀏覽範例網站</a>',
5 unsafe_allow_html=True
6 )
Nowsze Starsze