I’ve been trying to get this dropdown working for weeks with no success, What am I doing wrong?
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objects as go
import Macro
app = dash.Dash(name,)
app.layout = html.Div([
html.Label('Dropdown'),
dcc.Dropdown(
id='Dropdown_1',
options=[
{'label': 'US Index', 'value': Macro.US_Macro},
{'label': 'EU Index', 'value': Macro.EU_Macro},
],
value = Macro.US_Macro,
multi = True
),
html.H1(
children='Global Economies',
style={
'textAlign': 'center',
'color': '#7FDBFF'
}
),
dcc.Graph(id='Graph1'),
])
@app.callback(
Output(component_id=‘Graph1’, component_property=‘figure’),
[Input(component_id=‘Dropdown_1’, component_property= ‘value’)]
)
def update_graph(input_value):
return {
'data': [
go.Scatter(
x = input_value['x'],
y = input_value['y'],
mode='lines',
name= input_value['name'],
marker = input_value['marker']
)
],
'layout': go.Layout(
dragmode='pan',
)
}
if name == ‘main’:
app.run_server(debug=True)
Code from Macro.py which the above code is referencing:
US_Macro = {‘x’: US.index, ‘y’: US, ‘name’: ‘United States’, ‘marker’: {‘color’: ‘lime’}}
EU_Macro = {‘x’: EU.index, ‘y’: EU, ‘name’: ‘European Union’, ‘marker’: {‘color’: ‘blue’}}
where US and EU are pandas dataframes.
always I get invalid value passed to dropdown error, and the dropdown doesn’t even load.