Customizing the label to display a list returned from the server

What I’m trying to do:
I have a small question about displaying info using labels.

I’m using the display label procedure shown in the “Turning a Colab notebook into a web app”.
I have a para_summary_output label that is initially invisible. After the API call, it will display a String.

if summarize_article_para:
self.para_summary_output.visible = True
self.para_summary_output.text = summarize_article_para

My question is it possible to display a list sequentially or break down the String and display it in bullet point, without using much HTML and CSS as I really like to keep it drag-and-drop style :slight_smile: :smiley:

You could build the string by using a for loop to loop through the list and add the bullet point characters and carriage returns with the + operator.

Or use an f string.

What does your desired output look like?

Also check out the new rich text component
https://anvil.works/blog/richtext-component

2 Likes

Thanks for the reply!
So I’m able to return either a String or a list.
The expected output is something like

  • List item 1

  • List item 2

I’ll check out your suggestions, thanks !

So I split the String by full-stop.
text.split(".")
(You can use punkt from nltk and use that sentence tokenizer for a more accurate job)
Then I get a list and I joined elements in that list (each sentence) with a newline character
list_of_sentences = text.split(".")
formatted_text = “\n”.join(list_of_sentences)
So essentially formatted_text is still a String.
I got my functionality done, now just have to style it a bit better :slight_smile: Thanks for your help

1 Like

Suggestion: search for “Rich Text”. This brand-new feature handles bullet points et al via Markdown et al.

2 Likes