Please help me breakdown and understand this code

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html
import pandas as pd

df = pd.read_csv('https://gist.githubusercontent.com/chriddyp/c78bf172206ce24f77d6363a2d754b59/raw/c353e8ef842413cae56ae3920b8fd78468aa4cb2/usa-agricultural-exports-2011.csv')


def generate_table(dataframe, max_rows=10):
    return html.Table([
        html.Thead(
            html.Tr([html.Th(col) for col in dataframe.columns])
        ),
        html.Tbody([
            html.Tr([
                html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
            ]) for i in range(min(len(dataframe), max_rows))
        ])
    ])


app = Dash(__name__)

app.layout = html.Div([
    html.H4(children='US Agriculture Exports (2011)'),
    generate_table(df)
])

if __name__ == '__main__':
    app.run_server(debug=True)

I think its the syntax and layout, its extremely confusing, It looks like their is a lot of lists in there. Also what does iloc do? Does this: app = Dash(name) need to be in every file? is this calling from a method? if someone can break this down in simple way that would be great.

Thanks for any help
Total noob here.

Hi,

to answer your questions:

app = Dash(__name__) initiates the Dash app, usually this is done only once.

Once the app ist initiated, you can add content via the app.layout = 'SOMETHING'

In this case the content of the app is a html table which has been created from a *.csv file unsing pandas. Within pandas, pandas.iloc[] ist just a way of selecting rows and columns.

Here you find basic information about Dash:

This is the pandas.iloc[] help:

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iloc.html

Hi, thank you very much for the response. Thats helpful. I have decided to learn plotly as much as i can before moving onto dash. I only knew basics so will spend some time with it first.

Apprecitated