I am getting the above error while plotting the bar graphs and appending them to results. Is there any solution.
import dash
import pandas as pd
import plotly.express as px
from dash import Dash, html, dcc, Output, Input, MATCH
import dash_bootstrap_components as dbc
app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
df = pd.read_csv('assets/nights.csv')
ls1=df['City'].unique
app.layout = dbc.Container([
dcc.Dropdown(id='my-var', multi=True, persistence = True,
persistence_type = 'memory',
options=[{'label':x, 'value':x}
for x in ls1]),
html.Div('container','children')
)]
@app.callback(
Output('container', 'children'),
[Input("my-var", "value")]
)
def update_graphs(val):
d1=df.loc[df.City==var]
fig = px.bar(d1, x="City", y="Cost", barmode="group",)
output.append(dcc.Graph(id={'type': 'dynamic-graph','index': val },figure=fig))
output.append( html.Div(id={'type': 'container', 'index':val}))
return output
UnboundLocalError: local variable ‘fig’ referenced before assignment
Traceback (most recent call last):
File “C:\Users\Local\Temp\ipykernel_20424\180331076.py”, line 16, in update_graphsFile “C:\Users\Lib\site-packages\plotly\express_chart_types.py”, line 368, in bar
return make_figure(
File “C:\Users\Lib\site-packages\plotly\express_core.py”, line 2182, in make_figure
fig = init_figure(
File “C:\Users\Lib\site-packages\plotly\express_core.py”, line 2327, in init_figure
for annot in fig.layout.annotations:
UnboundLocalError: local variable ‘fig’ referenced before assignment