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

How do I create a display table for function driven data?

Hello,

I am working with a code that is basically a function with adjustable inputs. A coworker created the code and I am responsible for formatting. I am trying to create a display table for the function outputs and have no idea where to start. I’ve seen the table in section two of the Dash Users Guide and everything is still very confusing. I am very new to all of this so I apologize. Here is the code.

external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]

app = dash.Dash(name, external_stylesheets=external_stylesheets)
ending_value = ‘Ending Value Chart’

def generate_table():
return html.Table(
# Header

    # Body
    [html.Tr([
        html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
    ]) for i in range(min(len(dataframe), max_rows))]
)

app.layout = html.Div(children=[
html.H1(children=‘Historical Spending Analysis’),
generate_table(hsa(int(start_year),int(end_year),int(div_tax), int(spendrate))),
html.Div(‘Key Inputs & Assumptions’),
html.Label(‘Start Year’),
dcc.Input(id = ‘start-year’, value = 2000, type = ‘int’),
html.Label(‘End Year’),
dcc.Input(id = ‘end-year’, value = 2015, type = ‘int’),
html.Label(‘Div Tax’),
dcc.Input(id = ‘div-tax’, value = 20, type = ‘int’),
html.Label(‘Spend Rate’),
dcc.Input(id = ‘spendrate’, value = 75000, type = ‘int’),
dcc.Graph(id=‘example-graph’)

])

@app.callback(
dash.dependencies.Output(‘example-graph’, ‘figure’),
[dash.dependencies.Input(‘start-year’, ‘value’),
dash.dependencies.Input(‘end-year’, ‘value’),
dash.dependencies.Input(‘spendrate’, ‘value’),
dash.dependencies.Input(‘div-tax’, ‘value’)])
def update_graph(start_year,end_year,div_tax,spendrate):
new_df = hsa(int(start_year),int(end_year),int(div_tax), int(spendrate))
return {
‘data’: [
{‘x’: new_df.index, ‘y’: new_df[‘End Value’], ‘type’: ‘line’, ‘name’:start_year},
],
‘layout’: {
‘title’: start_year
}
}

if name == ‘main’:
app.run_server(debug=False)