Hello, I am trying to generate a table which has the number of columns specified in the dropdown component. I see the dropdown, but the table does not generate. My complete code is below and can be run directly. Any advice would be appreciated!
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import State, Input, Output
import dash_table
all_tickers = [‘s1’,‘s2’,‘s3’,‘s4’,‘s5’]
app = dash.Dash(name)
app.config[‘suppress_callback_exceptions’] = True
app.layout = html.Div([
html.Div(html.H3('Number of Proposed Portfolios')),
dcc.Dropdown(
id='prop-dropdown',
options=[
{'label': '1', 'value': '1'},
{'label': '2', 'value': '2'},
{'label': '3', 'value': '3'},
{'label': '4', 'value': '4'},
{'label': '5', 'value': '5'},
],
value='1'
),
html.Div(dash_table.DataTable(
id='proposed_tbl',
data=[{}],
editable=True,
filtering=True,
sorting=True),
),
])
@app.callback(
[Output(‘proposed_tbl’, ‘columns’),
Output(‘proposed_tbl’,‘data’)],
[Input(‘prop-dropdown’, ‘value’)])
def generate_tbl(n):
n = int(n)
params = ['Portfolio ’ + str(x) for x in range(1,n+1)]
columns1=(
[{‘id’: ‘Ticker’, ‘name’: ‘Ticker’}] +
[{‘id’: p, ‘name’: p} for p in params]),
data1=[
dict(Ticker=all_tickers[i], **{p: 0 for p in params})
for i in range(0, len(all_tickers))]
return columns1, data1
app.css.append_css({‘external_url’: ‘https://codepen.io/chriddyp/pen/bWLwgP.css’})
if name == ‘main’:
app.run_server(debug=False, port=8093)