Hi everyone!
I’m new on dash and I have some questions.
I want to plot curves that the user can chose by dropdowns (one for x axis and one for y axis).
I succeeded to plot a line for one value of the dropdown with the code below:
“”"
import pandas as pd
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.express as px
app = dash.Dash(name)
df=pd.read_csv(“data.csv”,sep=",",decimal=".",header=9)
print(df[:5])
#layout
app.layout=html.Div([
html.H1("results: ",
style={‘text_align’:‘center’}),
html.Label(‘Dropdown y axis’),
dcc.Dropdown(id=‘axe_y’,
options=[{‘label’:x,‘value’:x} for x in df.columns],
multi=False,
clearable=False,
value=‘Wind speed (m/s)’,
style={‘width’:‘40%’}
),
html.Label(‘Dropdown x axis’),
dcc.Dropdown(id=‘axe_x’,
options=[{‘label’:x,‘value’:x} for x in df.columns],
multi=False,
clearable=False,
value=’# Date and time’,
style={‘width’:‘40%’}
),
#html.Div(id=‘output_container’),
html.Br(),
dcc.Graph(id=‘graph_som’)
])
#callback
@app.callback(
Output(component_id=‘graph_som’,component_property=‘figure’),
[Input(component_id=‘axe_y’,component_property=‘value’),
Input(component_id=‘axe_x’,component_property=‘value’)]
)
def update_graph(axe_y_select,axe_x_select):
print(axe_y_select)
print(type(axe_y_select))
print(axe_x_select)
print(type(axe_x_select))
#remove some values
dff=df.copy()
dff=dff.dropna()
fig=px.line(data_frame=dff,x=dff[axe_x_select],y=dff[axe_y_select],template='plotly_dark')
return fig
if name == ‘main’:
app.run_server(debug=True)
“”"
I want to change my dropdowns to ‘multi’ and be able to have the different graphs represented.
Actually when I’m trying to have a multiple dropdown, I don’t succeed to plot the different values I select with the dropdown (especially different ‘y’ axis).
If somedody has an idea how it can be done, it would be useful!
Thanks!