I have a fairly simple px.bar
and px.scatter
graph that’s not showing up on the dashboard deployed to Google App Engine (their free tier), though it’s displaying fine locally.
Graphs that aren’t showing on the dashboard
Same graphs, locally
The three graphs that aren’t displaying properly (and the KPI cards to the side) are all lumped in one callback. It doesn’t load no matter how long I let it load for.
Not sure if the code matters but here’s the layout and the callback code (Dash.plotly) in case it’s needed.
dbc.Card(dbc.CardBody([
dbc.Row([
dbc.Col([
dbc.Stack([
html.H5("Select the number of customers to display"),
dcc.Slider(
id='filter-num-of-cust-slider-anal',
max=unique_customer_count_analysis,
marks=generate_marks(unique_customer_count_analysis, step=10),
min=1, value=10, step=1, tooltip={
"always_visible": True, "template": "{value} Customers"},
)
]),
dbc.Stack([
html.H5('Select the customer category'),
dcc.Dropdown(
options=customerCategory_dropdown_options,
id='filter-customer-category',
placeholder='Select customer category'
),
]),
dbc.Stack(
generate_highlight_cards("Average number of orders per week", html.P(id="val-avg-no-order-wk"), html.P(id="val-avg-no-order-wk-filter-txt"))
),
dbc.Stack(
generate_highlight_cards("Average order size", html.P(id='val-avg-ordersize-forAll'), html.P(id="val-avg-no-order-wk-filter-txt-2")),
),
dbc.Stack([
html.H5("Remove specific customers from the line graph"),
dcc.Dropdown(options=customer_dropdown_options_noAll,
id='filter-removeCustomers',
multi=True,
placeholder='Select customer to remove'
),
]),
], width=2, xl=2, xs=12),
dbc.Col([
dbc.Row([
dbc.Col([
dcc.Graph(id='fig-bar-customer-ord-habit'),
],width=6, xl=6, xs=12),
dbc.Col([
dcc.Graph(id='fig-bar-customer-ord-habit-orderPerWeek'),
], width=6,xl=6, xs=12),
dbc.Col([
dcc.Graph(id='fig-scatter-cust-orderHabit'),
], width=6, xl=6, xs=12),
dbc.Col([
dcc.Graph(figure=fig_cust_orderHabit_politicalCompass)
], width=6, xl=6, xs=12),
]),
],width=10, xl=10, xs=12)
])
])),
@dash.callback(
[Output('fig-bar-customer-ord-habit', 'figure'),
Output('fig-bar-customer-ord-habit-orderPerWeek', 'figure'),
Output('fig-scatter-cust-orderHabit', 'figure'),
Output('val-avg-no-order-wk','children'),
Output('val-avg-no-order-wk-filter-txt', 'children'),
Output('val-avg-ordersize-forAll', 'children'),
Output('val-avg-no-order-wk-filter-txt-2', 'children')],
[Input('filter-num-of-cust-slider-anal', 'value'),
Input('filter-customer-category', 'value'),
Input('filter-removeCustomers','value')]
)
def update_fig_cust_orderHabit_bar(num_of_cust_slider, filter_custCat, filter_cust_remove):
df_filtered = df_salesWithSegmentation_main.copy()
filter_category_text = 'All categories'
# Filter based on the category
if filter_custCat:
if 'ALL' in filter_custCat:
filter_category_text = "All categories"
filter_custCat = df_filtered['Category'].unique().tolist()
if isinstance(filter_custCat, str):
filter_custCat = [filter_custCat]
filter_category_text = filter_custCat
df_filtered = df_filtered[df_filtered['Category'].isin(filter_custCat)]
average_orders_per_week, average_order_size = process_customer_data(df_filtered)
customer_summary = pd.merge(average_orders_per_week, average_order_size, on='Customer').sort_values(by="Average Order Size", ascending=False)
df_sorted_averageOrderSize = customer_summary.sort_values(by='Average Order Size', ascending=False).head(num_of_cust_slider).reset_index(drop=True)
df_sorted_orderPerWeek = customer_summary.sort_values(by='Average Orders per Week', ascending=False).head(num_of_cust_slider).reset_index(drop=True)
# Create the bar graph
fig_cust_orderHabit_bar = px.bar(df_sorted_averageOrderSize, x='Customer', y="Average Order Size", title="Customer Average Order Size")
fig_cust_orderHabit_bar_orderPerWeek = px.bar(df_sorted_orderPerWeek, x='Customer', y="Average Orders per Week", title="Customer Average Number of Orders Per Week")
if filter_cust_remove is None:
filter_cust_remove = [] # Default to an empty list if None
customer_summary_removeCustomers = customer_summary[~customer_summary.Customer.isin(filter_cust_remove)]
fig_cust_orderHabit = px.scatter(customer_summary_removeCustomers, x='Average Orders per Week', y='Average Order Size', color='Customer', trendline='ols', trendline_scope="overall", title="Customer Average Number of Orders per Week vs. Average Order Size")
fig_cust_orderHabit.update_layout(legend=dict(font=dict(size= 8)))
val_avg_no_order_perWeek = round(average_orders_per_week['Average Orders per Week'].mean(),2)
val_avg_ord_size_forAll = round(average_order_size['Average Order Size'].mean(),0)
filter_category_text = "for: " + ''.join(filter_category_text)
return [fig_cust_orderHabit_bar, fig_cust_orderHabit_bar_orderPerWeek, fig_cust_orderHabit, val_avg_no_order_perWeek, filter_category_text, val_avg_ord_size_forAll, filter_category_text]
- The three graph uses the same dataset as the one on the bottom right, so the data’s loading.
The callback is also working for the filters to the left (updating customer category updates the number of customers to display), so I’m not sure if this a question about Dash, Google App Engine, or whether I just messed up somewhere. - I have other bar & scatter graphs on the dashboard too, so it’s not an issue with the libraries.
I see this error in the GCP logs
Traceback (most recent call last): File "/layers/google.python.pip/pip/lib/python3.11/site-packages/flask/app.py", line 1473, in wsgi_app response = self.full_dispatch_request()
And it seems like people are saying requirements.txt or runtime is incorrect, but my other graphs are working so I doubt it’s this…
Any pointers on how I can troubleshoot would be appreciated, thanks.
Peachy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.