Display text in various formats in the same component

I started to do some ‘conceptual’ tests with Anvil in the sense ‘can it be done’ and ‘it’s easy’, ‘it’s complicated’, ‘no way’ … as possible answers.

Generally, Anvil is fascinating.

I wonder how one would approach to the development of a form/widget to display text in various formats (italic, bold, different colors, fonts) in one element, like in dictionaries, e. g.

colloquium kəˈləʊkwɪəm/ noun: colloquium; plural noun: colloquia; plural noun: colloquiums

In similar environments, this is usually done by a kind of a dynamic “HTML element”, but I cannot find something similar in Anvil, except for the custom HTML template, but I cannot imagine how to develop a widget as I described above with this approach. Besides, the DB structure of dictionaries is quite complex, so the content of such a widget should be ‘highly’ dynamic, depending from the data some parts are displayed or not.

1 Like

Displaying a row of text elements is pretty simple: is the question regarding entering one word and returning the associated parts of speech?

NLTK (Natural Language ToolKit) has some functionality that could probably accomplish most of the above: see below for an example that singularizes plural nouns:
https://www.packtpub.com/mapt/book/big_data_and_business_intelligence/9781787285101/16/ch06lvl1sec069/singularizing-plural-nouns

You could just import nltk on a server-side function and you should be off to the races in 20 lines or fewer.

A nice overview of stemming in NLTK is here:
http://www.nltk.org/howto/stem.html

Cheers.

It’s more about displaying a row of text elements (labels) than stemming the terms.

I suppose each of labels can be formatted individually (italic, bold …), and the logic of displaying a specific text element or not is doable.

However, I played with all the containers but couldn’t find anything to set the width of a label (corresponding to its content, i. e. to the number of characters displayed) and to move labels on the right accordingly. The closest container that matches my needs is XY Panel, to dynamically move the labels.

…anyway, thanks for the tip about nltk, it will come handy for another purpose!

One possible way (just thinking out loud) …

Use a dynamic HTML form to create a “label” (span, div, whatever) to display the text.
You could then create a small JS function to update the HTML for that “label”.

Inside anvil, you can call JS functions (there’s an example somewhere on the forum, I’ll see if I can find it). So you could create the text inside anvil and send it to the JS function along with formatting instructions to be displayed.

I’ll have a go at an example when I get a moment.

That would be great. Using JS to update HTML is no problem for me, but injecting the data from Anvil / Python into it is another matter… :grinning:

Edit: this is probably the example you mentioned…? Dropdown Navigation

Yeah,but here’s a simpler version demonstrating what I think you are looking for :

https://anvil.works/ide#clone:BY744Q2WHGUZGEAV=7JY57JDQ3JWFVMUK4L2OMA6C

Basically, I create a form with custom HTML and a JS function in it.
I drag that form onto my main form (just like a text box for example).
Entering text and clicking submit should update the element (you can pack it with formatting)
I put the italic checkbox in there just to demonstrate formatting outside of the text box.

Does that help at all?

2 Likes

Yes, this is exactly what I need! Thanks, your advice is very helpful.

1 Like

You’re very welcome.
Glad to help.