Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Can I use a for loop to generate multiple figures in app.Layout()?

Hello!

If I have a csv file with unknown length, and I want to generate a scatter plot with each several rows of data. So I have to generate many scatter plot. How can I use a for loop in the app.Layout() to do that? Can I for loop callback as well?

I guess the answer is I can’t…:disappointed_relieved:

is there any way to generate multiple figures (depends on the variable length of data frame) without doing for loop?

You can. Just return a list in your function

@app.callback(Output('out', 'children'),
              [Input('...', '...')],
def clean_plot(...):
    lis=[]
    for i in ...:
        lis.append(html.Div(dcc.Graph(
                                  figure={'data':data_for_i})))
   return lis
1 Like