Announcing Dash Bio 1.0.0 🎉 : a one-stop-shop for bioinformatics and drug development visualizations.

Found the answer to "Ploting two graphs with one dropdown error Plotly - Dash - Pandas"

Continuing the discussion from Ploting two graphs with one dropdown error Plotly - Dash - Pandas:

The answer to my issue was to remove the brackets in the dropdown section regarding the default value - > should have been value = ‘11’. That took care of the exception being thrown. the following code works fine:

import pandas as pd
import plotly.express as px
import dash
import dash_core_components as dcc
import dash_html_components as html

df = pd.read_csv(r’C:/Time_Series_Study/Overtime2.csv’, delimiter = ‘,’, engine=‘python’)
df[‘Date’]=pd.to_datetime(df[‘Date’])
df.sort_values(by=[‘Date’], inplace=True, ascending=False)
MyProjects = df[‘Project’].unique()

app = dash.Dash()
app.layout = html.Div([
dcc.Dropdown(
id=‘demo-dropdown’,
options=[{‘label’: k, ‘value’: k} for k in MyProjects],
value=‘11’,
multi=False
),

html.Hr(),
dcc.Graph(id='graph1',),
html.Hr(),
dcc.Graph(id='graph2',
        )

])

@app.callback(
dash.dependencies.Output(‘graph1’, ‘figure’),
[dash.dependencies.Input(‘demo-dropdown’, ‘value’)])

def update_output(value):
ts = df[df[‘Project’].isin([value])]
ts1 = ts.groupby([‘Date’, ‘Project’])[[‘Regular Hours’]].sum().reset_index()
fig = px.line(ts1, x=“Date”, y=“Regular Hours”, color=‘Project’)
return fig

@app.callback(
dash.dependencies.Output(‘graph2’, ‘figure’),
[dash.dependencies.Input(‘demo-dropdown’, ‘value’)])

def update_output(value):
ts2 = df[df[‘Project’].isin([value])]
ts3 = ts2.groupby([‘Date’, ‘Project’])[[‘Overtime Hours’]].sum().reset_index()
fig2 = px.line(ts3, x=“Date”, y=“Overtime Hours”, color=‘Project’)
return fig2

if name == ‘ main ’:
app.run_server()