To create a public link, set `share=True` in `launch()`.
时间: 2024-06-18 19:03:02 浏览: 706
demo.launch(share=True) Please check your internet connection
在使用Python的`streamlit`库时,如果要创建一个公共链接,需要在`launch()`函数中设置参数`share=True`。这样,你就可以通过共享该链接,让其他人查看你的应用程序。在这里,`launch()`函数是启动Streamlit应用程序的入口点。下面是一个示例代码:
```python
import streamlit as st
def main():
st.write("Hello, world!")
if __name__ == "__main__":
main()
st.set_option('deprecation.showfileUploaderEncoding', False)
st.set_option('deprecation.showPyplotGlobalUse', False)
st.set_option('server.enableCORS', True)
st.set_page_config(page_title="My Streamlit App")
st.button("Click me")
st.selectbox("Select an option", ["Option 1", "Option 2", "Option 3"])
st.image("image.png", caption="A sample image")
st.write("This is a sample paragraph.")
st.markdown("## This is a sample markdown heading.")
st.latex(r"\sqrt{x^2 + y^2}")
st.pyplot()
st.bokeh_chart()
st.vega_lite_chart()
st.altair_chart()
st.plotly_chart()
st.graphviz_chart()
st.pie_chart()
st.area_chart()
st.bar_chart()
st.line_chart()
st.error("This is an error message.")
st.warning("This is a warning message.")
st.info("This is an informative message.")
st.success("This is a success message.")
# 设置共享选项
st.set_option('server.enableCORS', True)
# 启动应用程序并创建公共链接
public_url = ngrok.connect(port=8501)
st.write("URL:", public_url)
```
阅读全文