Dash fires all callbacks on launch. I suspect the problem is assoc. with not having input validation checks at the start of your callback. Ensure company and market have valid values before continuing, if not, return no_update, no_update.
To use no_update, include from dash.dash import no_update in your app.
Company and market arguments as passed as input by the user, and the datatable is updated based on them.
I tried to set default values and removed the default values with a conditioned the return statement : no_update. It didn’t seem to work. Not sure if I am doing it correctly, code below.
@app.callback([Output('tenant-table', 'data'),
Output('tenant-table', 'columns')],
[
Input("company-select", "value"),
Input("market-select", "value")
],
)
def render_table(company, market):
# Lookup Properties based on selections - Landlord and market.
if company is not None:
result = top_leads(company, market)
columns = [{"name": i, "id": i} for i in result.columns]
data = result.to_dict('records')
return (data, columns)
else:
return (no_update, no_update)
add the following at the start of the callback to see what the values are at startup. You check company but not market. Even though the args are passed as inputs by the user, this is not true when the app starts.
correct…you can also have top_leads do the error checking and return no_update accordingly (i.e. if you return None, or somethign else)…more than one way to do this - depends on what works best for you.
Right. That’s what I am attempting to do here with a conditioned function call and return statement. top_leads is only called when company & market are selected. However, it still isn’t rendering and throwing the error at launch.
def render_table(company, market):
print(f'company = {company} | market = {market}')
if None not in (company, market):
result = top_leads(company, market)
columns = [{"name": i, "id": i} for i in result.columns]
data = result.to_dict('records')
return (data, columns)
else:
return (no_update, no_update)
So, I tried a few things to resolve this, and even after input validation checks and return(no_update, no_update), I still get - cannot read property '0' of undefined error.
Additionally, I am also getting this error.
results is pandas dataframe that is being returned by function top_leads. It seems like this needs to be a list or a tuple?
Callback code:
@app.callback([Output('table', 'data'),
Output('table', 'columns')],
[
Input("company-select", "value"),
Input("market-select", "value")
],
)
def render_table(company, market):
print(f'company = {company} | market = {market}')
if company == '' and market == '':
print('no selection')
return (no_update, no_update)
else:
result = top_leads(company, market)
columns = [{"name": i, "id": i} for i in result.columns]
data = result.to_dict('records')
return (data, columns)
I’m having the same issues. I’ve added prints for all arguments to the callbacks. All looks good. I’ve also used a different .csv in case I inadvertently modified data. Still same issue. Wish you luck. Please post your findings if you find a solution. This error message falls short of identifying the problem.
Lew
Not sure if this helps. Here’s my layoyut.
app.layout = html.Div([
dcc.Graph(id=‘jb4-graph’, figure=initial_fig),
dcc.Slider(
id=‘jb4-slider’,
min=min_ts,
max=max_ts,
value=min_ts,
step=0.25
),
html.Div(id=‘jb4-slider-value-div’)
])
The figure for the graph is a line graph. The slider for the layout changes the x access. When the slider is moved, the line graph moves left or right. Previously I did not define an initial figure for the graph and got the prop 0 error. When I defined the initial figure it worked. Perhaps this is because the callbacks are called on launch and the figure property has not been assigned.