How to bind f string?

Let’s start with what I’ve got so far, I’ll break them down into examples with #3 being the goal.
In Example 1 you click a button to add it to the Dict in my data base which works great.


image
In example 2, you can click on fruit or veggies and it will break that Dict to a list of buttons that you can click and they remove that item from the Dict. Works great except, the buttons don’t leave without refreshing the page(tried soo many things with this), you cant combine them with an image or text box, you get an error that they are out of range once removed.

Example 3, a simple repeating panel that does what example 2 does, except the goal being a repeating panel that can link with items like pictures in a nice row. The issue is how can i bind the f strings from a Dict. I’ve tried looking through this forum with no luck. Any help would be amazing.

image

Here is a copy of the app.
https://anvil.works/build#clone:BZ67Y5CBKZG5QWGW=XMR5IY6IF4NLCGCUMLERDO6D

What do you mean by “f strings from a Dict”?

In example 2, the Dict is broken into f strings(Formatted strings). But I’m trying to do it with repeating panels.

 Fruit_F = app_tables.list_r.get(Type="Fruit")    
 items_F = Fruit_F['StoreInfo']
 Fruit_F['Column2'] == True
  
  
 for element in (items_F):

  buttonF = Button(text=f"{element['Name']}")
  self.add_component(buttonF)
  buttonF.add_event_handler('click',self.buttonF_click)

ive got it now where it does bring back the dict formatted, however its only making 1 of the items from my dict
Fruit_F = app_tables.list_r.get(Type=“Fruit”)
items_F = Fruit_F[‘StoreInfo’]

 for element in (items_F):

  self.label_1.text = f"{element['Name']}"

I’m sorry, but I cloned the app and I still don’t understand what you are trying to do.

What is the input?
What is the desired output?


F-strings are expressions that generate strings. The dictionary stores a value, the string resulting from the f-string, not the f-string expression. It doesn’t know whether the string has been generated by an f-string expression, a function or what else.

Here you are using an f-string expression to format the string element['Name'] into the same string. This code would be identical to Button(text=element['Name']), just like 'abc' == f"{'abc'}"

This would be the desired outcome


The input is the Dict from my database. i just want to take each entry from the DIct to be its own line in the repeating panel.

This is suspect, since you are overwriting the contents of label_1 each time through the loop. You’re going to lose all but the last write to label_1.

How do i avoid this? How do i bind this data to label_1 postion?

The 4 things I see on your snapshot look like the 4 rows of the Items table, but your app only searches from the List_r table.

I also see that your app does a search from the code inside the ItemTemplate2 template.

The correct way to use databinding with a repeating panel is to create a list of dictionaries and assign it to items of the repeating panel. The repeating panel will take care of assigning each dictionary from the list to one instance of its template form. In simple cases like this you don’t need any code in the template form.

Try to follow the tutorial linked here. It’s old, but it’s still a good way to understand what the databinding does with a repeating panel and the template forms contained in it.