Streamlit Annotated Text

4.0.2 · active · verified Wed Apr 15

st-annotated-text is a simple component designed to display annotated text directly within Streamlit applications. Currently at version 4.0.2, the library provides an intuitive way to highlight and label parts of text. Releases are typically driven by compatibility fixes and minor feature enhancements.

Warnings

Install

Imports

Quickstart

This example demonstrates basic usage, including simple annotations, custom background colors, and nested list structures for more complex text segments.

import streamlit as st
from annotated_text import annotated_text

st.set_page_config(layout='centered', page_title='Annotated Text Demo')

st.title("My Annotated Text App")

annotated_text(
    "This ", 
    ("is", "Verb"), 
    " some ", 
    ("annotated", "Adj"), 
    ("text", "Noun"), 
    " for those of ", 
    ("you", "Pronoun"), 
    " who ", 
    ("like", "Verb"), 
    " this sort of ", 
    ("thing", "Noun"),
    "."
)

st.subheader("Custom Colors and No Label")
annotated_text(
    "And here's a ",
    ("word", "", "#faf"),
    " with a fancy background but no label."
)

st.subheader("Nested Lists for Complex Structures")
my_complex_list = [
    "Hello ", 
    ["my ", ("dear", "Adj"), " "],
    ("world", "Noun"),
    "."
]
annotated_text(my_complex_list)

view raw JSON →