Hello Sempah,
thank you so much for the help,
i was able to fix the issues and now trying to divide my app into tabs.
i encountered this error:
“callback() takes from 2 to 4 positional arguments but 5 were given”
even though i have only 3 arguments in the callback,
and why can i only input 2 to any ways?
my code:
#DASH creation
#Style component(select file as link)
=============================================================================
app = dash.Dash(name, external_stylesheets=external_stylesheets)
=============================================================================
app = dash.Dash()
colors = dict(bg = ‘#000000’,text = ‘#7FDBFF’)
#%%call for execution
external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]
app = dash.Dash(name, external_stylesheets=external_stylesheets)
app.layout = html.Div([dcc.Store(id=‘dfs’),
dcc.Upload(id=‘upload-data’,
children=html.Div(['Drag and Drop or click to ',
html.A(‘Select Files’)]),
style = dict( width = ‘100%’,
height = ‘60px’,
lineHeight = ‘60px’,
borderWidth = ‘1px’,
borderStyle = ‘dashed’,
borderRadius = ‘5px’,
textAlign = ‘center’),
# Allow multiple files to be uploaded
multiple=True
),
html.Div([dcc.Dropdown(id=‘DM-picker’)]),
html.H1(‘Dash Tabs component demo’),
dcc.Tabs(id=“tabs-example”, value=‘tab-1-example’, children=[
dcc.Tab(label=‘Tab One’, value=‘tab-1-example’),
dcc.Tab(label=‘Tab Two’, value=‘tab-2-example’),
dcc.Tab(label=‘Tab Three’, value=‘tab-3-example’),
]),
html.Div(id=‘tabs-content-example’)
])
#%%Store data as JSON string for future use
@app.callback(Output(‘dfs’, ‘data’),
[Input(‘upload-data’, ‘contents’)])
def update_output(list_of_contents):
dfs = parse_contents(list_of_contents)
dfs_json =
for item in dfs:
dfs_json.append(df2json(item))
return dfs_json
#%% DM picker to use as dropdown filter
@app.callback(Output(‘DM-picker’, ‘options’),
[Input(‘dfs’, ‘data’)])
def dm_pick(data):
dfs =
for item in data:
dfs.append(json2df(item))
dm_table = dfs[0]
header_table = dfs[1]
data_table = dfs[2]
dm_data_set = dfs[3]
dm_names = []
for dm in list(dm_table['Concatenated Measurement']):
dm_names.append({'label': dm , 'value': dm})
return dm_names
#%%Tabs structure
@app.callback(Output(‘tabs-content-example’, ‘children’),
[Input(‘tabs-example’, ‘value’)],
[Input(‘DM-picker’, ‘value’)],
[State(‘dfs’, ‘data’)])
def render_content(tab,selected_dm,data):
scatter = update_scatter(selected_dm,data)
hist = update_hist(selected_dm,data)
if tab == ‘tab-1-example’:
return html.Div([
html.H3(‘Tab content 1’),
html.Div([dcc.Graph(id=‘graph-1-tabs’,figure=scatter)],
style=dict(width = ‘48%’,display = ‘inline-block’)),
html.Div([dcc.Graph(id=‘graph-2-tabs’,figure=hist)],
style=dict(width = ‘48%’,display = ‘inline-block’))
])
elif tab == ‘tab-2-example’:
return html.Div([
html.H3(‘Tab content 2’),
html.Div([dcc.Graph(id=‘graph-1-tabs’,figure=hist)],
style=dict(width = ‘48%’,display = ‘inline-block’)),
html.Div([dcc.Graph(id=‘graph-2-tabs’,figure=scatter)],
style=dict(width = ‘48%’,display = ‘inline-block’))
])
elif tab == ‘tab-3-example’:
return html.Div([
html.H3(‘Tab content 3’),
html.Div([dcc.Graph(id=‘graph-1-tabs’,figure=hist)],
style=dict(width = ‘48%’,display = ‘inline-block’)),
html.Div([dcc.Graph(id=‘graph-2-tabs’,figure=scatter)],
style=dict(width = ‘48%’,display = ‘inline-block’))
])
if name == ‘main’:
app.run_server()