Skip to content

πŸ”–Β Β Tags

Submitted by Maggie Liu

Summary

Display tags like github issues!

Functions

tagger_component

Displays tags next to your text.

Parameters:

Name Type Description Default
content str

Content to be tagged

required
tags list

A list of tags to be displayed next to the content

required
color_name list[str] | str | None

A list or a string that indicates the color of tags. Choose from lightblue, orange, bluegreen, blue, violet, red, green, yellow

None
text_color_name list[str] | str | None

A list or a string that indicates the text color of tags.

None
Source code in src/streamlit_extras/tags/__init__.py
@extra
def tagger_component(
    content: str,
    tags: list[str],
    color_name: list[str] | str | None = None,
    text_color_name: list[str] | str | None = None,
):
    """
    Displays tags next to your text.

    Args:
        content (str): Content to be tagged
        tags (list): A list of tags to be displayed next to the content
        color_name: A list or a string that indicates the color of tags.
            Choose from lightblue, orange, bluegreen, blue, violet, red, green, yellow
        text_color_name: A list or a string that indicates the text color of tags.
    """
    if isinstance(color_name, list) and len(color_name) != len(tags):
        raise ValueError(
            f"color_name must be the same length as tags. "
            f"len(color_name) = {len(color_name)}, len(tags) = {len(tags)}"
        )
    if isinstance(text_color_name, list) and len(text_color_name) != len(tags):
        raise ValueError(
            f"text_color_name must be the same length as tags. "
            f"len(text_color_name) = {len(text_color_name)}, len(tags) = {len(tags)}"
        )
    tags_html = _get_html(content, tags, color_name, text_color_name)

    st.write(tags_html, unsafe_allow_html=True)

Import:

from streamlit_extras.tags import tagger_component # (1)!
  1. You should add this to the top of your .py file πŸ› 

Examples

example

def example():
    tagger_component("Here is a feature request", ["p2", "🚩triaged", "backlog"])
    tagger_component(
        "Here are colored tags",
        ["turtle", "rabbit", "lion"],
        color_name=["blue", "orange", "lightblue"],
    )
    tagger_component(
        "Annotate the feature",
        ["hallucination"],
        color_name=["blue"],
    )
Output (beta)