繁体   English   中英

如何在 Streamlit 中创建带有超链接的按钮?

[英]How to create a button with Hyperlink in Streamlit?

我想在Streamlit中创建一个带有超链接的按钮。 我想也许可以通过以下语法使用st.button[Click Here](https://stackoverflow.com) 但不幸的是,这没有成功,它只显示文本,并没有将其作为超链接。 我找到了这个解决方法,但这不再有效。 我不想将st.markdown与超链接一起使用,因为它不会创建按钮。 这是一个可重现的例子:

"""
# Streamlit app
"""

import streamlit as st
import pandas as pd

# Button with hyperlink
st.button('[Click Here](https://stackoverflow.com)')

Output:

在此处输入图像描述

如您所见,它不会创建超链接。 所以我想知道是否有人知道如何在 Streamlit 中创建带有超链接的按钮?

您可以使用 markdown、 abutton标签。

import streamlit as st

url = 'https://stackoverflow.com'

st.markdown(f'''
<a href={url}><button style="background-color:GreenYellow;">Stackoverflow</button></a>
''',
unsafe_allow_html=True)

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM