Displaying Python Lists

Hi,

I’ve had a go at doing this myself but I think I’m being silly. I have a python list which contains filenames, I want to display each of these items on the dash.

I’ve been trying to the use the function LI() from the dash_html_components library.

I was thinking I might need to convert the python list into a html list, which I can brute force but was wondering if there was a different way.

My end goal is for each item in the list to be a link that the user can click and download, but just want to do this first.

Thanks for your help,
Shan

1 Like

Hi, of course you can do that. Not sure how you want to to format the list, maybe like this:

  1. item1
  2. item2
  3. item3

The code is:

dcc.Markdown('''
1. [item1](http://link1)
2. [item2](http://link2)
3. [item3](http://link3)
''')

Thanks is there a quick way to convert the Python List I have into a markdown one?

You can do it with a list comprehension: html.Ul([html.Li(x) for x in my_list])

7 Likes

Thanks that worked a treat!

@Philippe what if the Python list is inside of a callback?

that really helped,you’re a god

Still helping in 2020

return the html component like:

dbc.Alert("", color="info", id='log-output')

# Logfile Output Callback
@app.callback(dash.dependencies.Output('log-output', 'children'),
              [dash.dependencies.Input('interval1', 'n_intervals')])
def update_interval(n):
    file = open('file.log', 'r')
    lines = file.read().splitlines()
    file.close()
    return html.Ul([html.Li(x) for x in lines])

More on…List Comprehension