Skip to main content

Text Annotator

Use text annotator when you need to highlight text phrases. Useful for NLP.

text_annotator-0

q.page['example'] = ui.form_card(box='1 1 4 10', items=[
ui.text_annotator(
name='annotator',
title='Select text to annotate',
tags=[
ui.text_annotator_tag(name='p', label='Person', color='#F1CBCB'),
ui.text_annotator_tag(name='o', label='Org', color='#CAEACA'),
],
items=[
ui.text_annotator_item(text='Killer Mike', tag='p'),
ui.text_annotator_item(text=' is a member, of the hip hop supergroup '), # no tag
ui.text_annotator_item(text='Run the Jewels', tag='o'),
],
)
])

Readonly

If you wish to prevent user interaction with annotator component, set readonly attribute to True.

text_annotator-1

q.page['example'] = ui.form_card(box='1 1 4 10', items=[
ui.text_annotator(
name='annotator',
title='Select text to annotate',
readonly=True,
tags=[
ui.text_annotator_tag(name='p', label='Person', color='#F1CBCB'),
ui.text_annotator_tag(name='o', label='Org', color='#CAEACA'),
],
items=[
ui.text_annotator_item(text='Killer Mike', tag='p'),
ui.text_annotator_item(text=' is a member, of the hip hop supergroup '), # no tag
ui.text_annotator_item(text='Run the Jewels', tag='o'),
],
)
])

With line breaks

Use the \n or \r escape characters if you wish to force the line breaks within the text.

text_annotator-2

multiline_text='''
I am
multiline
text
'''

q.page['example'] = ui.form_card(box='1 1 4 10', items=[
ui.text_annotator(
name='annotator',
title='Select text to annotate',
tags=[
ui.text_annotator_tag(name='p', label='Tag 1', color='#CAEACA'),
ui.text_annotator_tag(name='n', label='Tag 2', color='#F1CBCB'),
],
items=[
ui.text_annotator_item(text='I am\nmultiline\rtext'),
ui.text_annotator_item(text=multiline_text),
],
)
])