What are the different text elements in streamlit

In this recipe, we will learn what are the different text elements in Streamlit. We will also take a look at a simple Streamlit application consisting of text elements.

Recipe Objective: What are the different text elements in Streamlit?

Apart from st.write there are several other ways of displaying text in Streamlit.
Normally, any streamlit app starts with a call to st.title to display the app's title.
Following this there are two heading levels that can be used- st.header and st.subheader.
Pure, fixed-width or preformatted text can be displayed using st.text.
Markdown can be displayed using st.markdown.
To display text in small font st.caption can be used.
st.latex is used to display mathematical equations.

Code:

#importing streamlit library
import streamlit as st

#Display text in title formatting
st.title('This is a title')

#Display text in header formatting
st.header('This is a header')

#Display text in subheader formatting
st.subheader('This is a subheader')

#Display string formatted as Markdown.
st.markdown('_Markdown_')

#Display Write fixed-width and preformatted text
st.text('This is sample text')

#Display mathematical expressions formatted as LaTeX
st.latex(r''' e^{i\pi} + 1 = 10 ''')

#Display text in small font
st.caption('This is a caption')

To run the app, either create an appname.py file with the above code using any text editor, or if you are using a jupyter notebook, you need to download your .ipynb notebook as a Python (.py) file and run the same using the "streamlit run appname.py" command. Once you run the command, the app will automatically open in your default browser.

What Users are saying..

profile image

Jingwei Li

Graduate Research assistance at Stony Brook University
linkedin profile url

ProjectPro is an awesome platform that helps me learn much hands-on industrial experience with a step-by-step walkthrough of projects. There are two primary paths to learn: Data Science and Big Data.... Read More

Relevant Projects

Build a Logistic Regression Model in Python from Scratch
Regression project to implement logistic regression in python from scratch on streaming app data.

Build an Image Segmentation Model using Amazon SageMaker
In this Machine Learning Project, you will learn to implement the UNet Architecture and build an Image Segmentation Model using Amazon SageMaker

PyTorch Project to Build a GAN Model on MNIST Dataset
In this deep learning project, you will learn how to build a GAN Model on MNIST Dataset for generating new images of handwritten digits.

Build Multi Class Text Classification Models with RNN and LSTM
In this Deep Learning Project, you will use the customer complaints data about consumer financial products to build multi-class text classification models using RNN and LSTM.

Learn How to Build PyTorch Neural Networks from Scratch
In this deep learning project, you will learn how to build PyTorch neural networks from scratch.

Personalized Medicine: Redefining Cancer Treatment
In this Personalized Medicine Machine Learning Project you will learn to classify genetic mutations on the basis of medical literature into 9 classes.

Abstractive Text Summarization using Transformers-BART Model
Deep Learning Project to implement an Abstractive Text Summarizer using Google's Transformers-BART Model to generate news article headlines.

Medical Image Segmentation Deep Learning Project
In this deep learning project, you will learn to implement Unet++ models for medical image segmentation to detect and classify colorectal polyps.

NLP Project for Beginners on Text Processing and Classification
This Project Explains the Basic Text Preprocessing and How to Build a Classification Model in Python

Forecasting Business KPI's with Tensorflow and Python
In this machine learning project, you will use the video clip of an IPL match played between CSK and RCB to forecast key performance indicators like the number of appearances of a brand logo, the frames, and the shortest and longest area percentage in the video.