Hi, I’m new to Dash, Plotly and Python and I 'm trying to do a line chart with a multi options dropdown but the options in the dropdown are not filtering the lines in the chart, instead, it have multiple lines on the right side of the line chart which are doing the work the dropdown supposed to do. Could someone have any tips to help me?
Here is the code:
import pandas as pd
import plotly
import plotly.express as px
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
app = dash.Dash(name)
df = pd.read_csv(‘Gráfico2(11.10).csv’, encoding=‘UTF-8’, sep=’;’)
app.layout = html.Div([html.Div([html.H1(children=‘Comparação semanal dos principais destinos brasileiros:’),
html.Label(['Escolha as cidades para comparar:'],
style={'font-weight': 'bold'}),
dcc.Dropdown(id='cidades',
options=[{'label': x, 'value': x}
for x in df.sort_values('CIDADE')['CIDADE'].unique()],
value=['Brasil'],
multi=True,
disabled=False,
clearable=False,
searchable=True,
placeholder='Escolha a cidade...',
style={'width': '100%',
'height': '1000%'}),
]),
html.Div([dcc.Graph(id='grafico')]),
])
@ app.callback(
Output('grafico', 'figure'),
[Input('cidades', 'value')]
)
def update_graph(cidades):
dff = df
fig = px.line(data_frame=dff, x="DIA", y="PCTG",
color='CIDADE')
fig.update_layout(xaxis_title='Semanas',
yaxis_title='Mudanças no interesse pelas buscas de voos (%)')
return fig
if name == ‘main’:
app.run_server(debug=True)`Preformatted text`