Text elements

Streamlit 应用通常以调用 st.title 来设置应用的标题开始。之后,您可以使用两种标题级别:st.headerst.subheader

纯文本使用st.text输入,Markdown使用st.markdown输入。

我们还提供了一个称为st.write的“瑞士军刀”命令,它接受多个参数和多种数据类型。如上所述,您也可以使用magic commands来代替st.write

screenshot

Markdown

显示格式化为Markdown的字符串。

st.markdown("Hello **world**!")
screenshot

标题

以标题格式显示文本。

st.title("The app title")
screenshot

标题

在标题格式中显示文本。

st.header("This is a header")
screenshot

子标题

以子标题格式显示文本。

st.subheader("This is a subheader")
screenshot

标题

以小字体显示文本。

st.caption("This is written small caption text")
screenshot

代码块

显示一个带有可选语法高亮的代码块。

st.code("a = 1234")
screenshot

回声

在应用程序上显示一些代码,然后执行它。对于教程很有用。

with st.echo(): st.write('This code will be printed')
screenshot

预格式化文本

编写固定宽度和预格式化的文本。

st.text("Hello world")
screenshot

LaTeX

显示格式化为LaTeX的数学表达式。

st.latex("\int a x^2 \,dx")
screenshot

分隔线

显示一条水平线。

st.divider()

第三方组件

这些是由我们可爱的社区创建的精选组件。更多示例和灵感,请查看我们的 组件库 Streamlit 扩展

screenshot

注释文本

在Streamlit应用程序中显示带注释的文本。由@tvst创建。

annotated_text("This ", ("is", "verb"), " some ", ("annotated", "adj"), ("text", "noun"), " for those of ", ("you", "pronoun"), " who ", ("like", "verb"), " this sort of ", ("thing", "noun"), ".")
screenshot

可绘制画布

提供一个使用Fabric.js的绘图画布。由@andfanilo创建。

st_canvas(fill_color="rgba(255, 165, 0, 0.3)", stroke_width=stroke_width, stroke_color=stroke_color, background_color=bg_color, background_image=Image.open(bg_image) if bg_image else None, update_streamlit=realtime_update, height=150, drawing_mode=drawing_mode, point_display_radius=point_display_radius if drawing_mode == 'point' else 0, key="canvas",)
screenshot

标签

为您的Streamlit应用程序添加标签。由@gagan3012创建。

st_tags(label='# Enter Keywords:', text='Press enter to add more', value=['Zero', 'One', 'Two'], suggestions=['five', 'six', 'seven', 'eight', 'nine', 'three', 'eleven', 'ten', 'four'], maxtags = 4, key='1')
forum

还有问题吗?

我们的 论坛 充满了有用的信息和Streamlit专家。