Hello all,
I have started using Dash for a dynamic modelling application. I was successful in producing a really nice functionality so far, but it has grown bigger and I need dynamic tabs.
Among many of the online queries this one seems the most relevant: dcc.Tabs: Filling tabs with dynamic content. How to organize the callbacks?.
I tried the same approach using reproducible Hello World example, and I get the error :"TypeError: Unexpected keyword argument ‘tabs’.
Here is the code:
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import dash_table_experiments as dt
import flask
import pandas as pd
import time
import os
server = flask.Flask('app')
server.secret_key = os.environ.get('secret_key', 'secret')
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/hello-world-stock.csv')
app = dash.Dash('app', server=server)
app.config['suppress_callback_exceptions'] = True
app.scripts.config.serve_locally = False
dcc._js_dist[0]['external_url'] = 'https://cdn.plot.ly/plotly-basic-latest.min.js'
app.layout = html.Div([
html.Div([dcc.Dropdown(
id='dropdown',
options=[{'label': 'Option 1', 'value': 1},
{'label': 'Option 2', 'value': 2}],
value='1',
)]),
dcc.Tabs(tabs=[{'label': 'Tab 1', 'value': 1},
{'label': 'Tab 2', 'value': 2}],
value=3,
id='tabs',
),
html.Div(id='tab-output')
])
@app.callback(Output('tab-output', 'children'), [Input('tabs', 'value')])
def display_content(value):
if value == 1:
return html.Div([
html.H1('Stock Tickers'),
dcc.Dropdown(
id='my-dropdown',
options=[
{'label': 'Tesla', 'value': 'TSLA'},
{'label': 'Apple', 'value': 'AAPL'},
{'label': 'Coke', 'value': 'COKE'}
],
value='TSLA'
),
dcc.Graph(id='my-graph')
], className="container")
elif value == 2:
return html.Div([dt.DataTable(id='table')]) #etc. etc.
@app.callback(Output('my-graph', 'figure'),
[Input('my-dropdown', 'value')])
def update_graph(selected_dropdown_value):
dff = df[df['Stock'] == selected_dropdown_value]
return {
'data': [{
'x': dff.Date,
'y': dff.Close,
'line': {
'width': 3,
'shape': 'spline'
}
}],
'layout': {
'margin': {
'l': 30,
'r': 20,
'b': 30,
't': 20
}
}
}
if __name__ == '__main__':
app.run_server()
If anybody can help, I would be very grateful - I cannot continue my project without solving this.
Thanks!