I am new to Dash. I am trying to plot a simple line plot and add a dropdown to change the data which comes from a dataframe (which is nested in a dictionary with other dataframes). Here is the dataframe:
df_vals['corn']
time 2m_temp_prod 2m_temp_area total_precip_prod total_precip_area
0 2020-09-19 00:00:00 299.346777 299.799234 0.000000 0.000000
1 2020-09-19 06:00:00 294.039512 294.443352 0.191070 0.286952
2 2020-09-19 12:00:00 292.959274 293.182931 0.155765 0.216606
3 2020-09-19 18:00:00 301.318046 301.767516 0.421768 0.485691
4 2020-09-20 00:00:00 300.623567 300.979650 0.363572 0.501164
... ... ... ... ... ...
56 2020-10-03 00:00:00 301.177141 301.052273 0.371209 0.408515
57 2020-10-03 06:00:00 295.874298 295.720135 0.281793 0.300564
58 2020-10-03 12:00:00 293.838787 293.686738 0.586887 0.549365
59 2020-10-03 18:00:00 302.384474 302.191334 0.492712 0.493798
60 2020-10-04 00:00:00 300.920766 300.817993 0.522374 0.531138
Here is the code where I attempt the plot.
app = JupyterDash(__name__)
cols=df_vals['corn'].columns[1:]
app.layout = html.Div([
html.Div([
html.Div([
dcc.Dropdown(
id='variables',
options=[{'label': i, 'value': i} for i in cols],
value='2m_temp_prod'
)
]),
dcc.Graph(id='plot')])
])
@app.callback(
Output('plot', 'figure'),
[Input('variables', 'value')])
def update_graph(variable_name):
fig=px.line(x=df_vals['corn']['time'], y=df_vals['corn'][variable_name])
return fig
app.run_server(mode='inline')
This makes a plot with the correct dropdown options, but there is no data being plotted. What am I doing wrong here? Trying to follow a tutorial on the Dash website, but appear to be tripping up something.