Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

Appending dbc object to a list

$
0
0

I’m trying to do this:

popoverBody=[]
for key in theText:
    popoverBody.append(dbc.ListGroupItemText(theText[key]))

…in order to create this:

html.Div([ 
        dbc.PopoverHeader("Header Text"),
        dbc.PopoverBody(popoverBody)
])

Not happening. When I investigate, I’m getting this:

print(popoverBody)
    [
        ListGroupItemText("Text 1"), 
        ListGroupItemText("Text 2"), 
        ListGroupItemText("Text 3"), 
        ListGroupItemText("Text 4")
    ]

…which list does NOT contain dbc.ListGroupItemText items.

It seems that pushing the dbc.ListGroupItemText object loses something when pushed to/read from a list (tried this with html.Li items w/same result, incidentally - the ‘html.’ is stripped away in the list).

Going the literal route doesn’t help, either:

for key in theText:
    popBody.append('dbc.ListGroupItemText("' + theText[key] + '"),')
print(popoverBody)
[
    'dbc.ListGroupItemText("Text 1")', 
    'dbc.ListGroupItemText("Text 2")', 
    'dbc.ListGroupItemText("Text 3")', 
    'dbc.ListGroupItemText("Text 4")'
]

Doing it manually works just fine…

html.Div([ 
        dbc.PopoverHeader("Header Text"),
        dbc.PopoverBody([
           dbc.ListGroupItemText("Text 1"),
           dbc.ListGroupItemText("Text 2"), 
           dbc.ListGroupItemText("Text 3"), 
           dbc.ListGroupItemText("Text 4")
        ])
])

Any ideas? Probably showing my ignorance of basic Python here so apologies in advance if so.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 6271

Trending Articles