✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Displaying Python Lists


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,

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:

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])


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()
    return html.Ul([html.Li(x) for x in lines])

More on…List Comprehension