timmy ревизий этого фрагмента 10 months ago. К ревизии
1 file changed, 16 insertions
streamlit_embed_html.py(файл создан)
| @@ -0,0 +1,16 @@ | |||
| 1 | + | import streamlit as st | |
| 2 | + | import streamlit.components.v1 as components | |
| 3 | + | ||
| 4 | + | st.title("嵌入 HTML 內容的範例") | |
| 5 | + | ||
| 6 | + | # 使用 components.html() 來插入自訂 HTML | |
| 7 | + | html_code = """ | |
| 8 | + | <div style="text-align:center;"> | |
| 9 | + | <h2 style="color: blue;">這是自訂的 HTML 標題</h2> | |
| 10 | + | <p style="font-size: 18px;">這是一段內嵌的 HTML 內容,你可以自由修改。</p> | |
| 11 | + | <button onclick="alert('你點擊了按鈕!')">點我一下</button> | |
| 12 | + | </div> | |
| 13 | + | """ | |
| 14 | + | ||
| 15 | + | # 透過 components.html() 來顯示 HTML,height 參數設定顯示區域的高度 | |
| 16 | + | components.html(html_code, height=200) | |
timmy ревизий этого фрагмента 10 months ago. К ревизии
1 file changed, 0 insertions, 0 deletions
gistfile1.txt переименован в streamlit_html_example.py
Файл переименован без изменений
timmy ревизий этого фрагмента 10 months ago. К ревизии
1 file changed, 13 insertions
gistfile1.txt(файл создан)
| @@ -0,0 +1,13 @@ | |||
| 1 | + | import streamlit as st | |
| 2 | + | ||
| 3 | + | st.title("嵌入 HTML 的範例") | |
| 4 | + | ||
| 5 | + | html_code = """ | |
| 6 | + | <div style="border: 2px solid #4CAF50; padding: 10px; border-radius: 5px;"> | |
| 7 | + | <h2 style="color: #4CAF50;">這是一個 HTML 區塊</h2> | |
| 8 | + | <p>你可以在這裡嵌入 HTML, CSS, 甚至 JavaScript。</p> | |
| 9 | + | <button onclick="alert('Hello, Streamlit!')">點擊我</button> | |
| 10 | + | </div> | |
| 11 | + | """ | |
| 12 | + | ||
| 13 | + | st.components.v1.html(html_code, height=200) | |