Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dash not working on dev site #1251

Closed
nichhk opened this issue Jun 22, 2022 · 7 comments · Fixed by #1256
Closed

Dash not working on dev site #1251

nichhk opened this issue Jun 22, 2022 · 7 comments · Fixed by #1256
Assignees

Comments

@nichhk
Copy link
Member

nichhk commented Jun 22, 2022

I checked the logs for the server, and it gives an error like this:

[22/Jun/2022:02:06:36] File "/app/dashboards/neighborhood_recent.py", line 70, in <module>
[22/Jun/2022:02:06:36] labels=LABELS,
[22/Jun/2022:02:06:36] File "/usr/local/lib/python3.7/site-packages/plotly/express/_chart_types.py", line 252, in line
[22/Jun/2022:02:06:36] return make_figure(args=locals(), constructor=go.Scatter)
[22/Jun/2022:02:06:36] File "/usr/local/lib/python3.7/site-packages/plotly/express/_core.py", line 1889, in make_figure
[22/Jun/2022:02:06:36] for val in sorted_group_values[m.grouper]:
[22/Jun/2022:02:06:36] KeyError: 'typeName'

Looking at git blame for "neighborhood_recent.py", it looks like PR #1221 is the most recent change for line 70.

@nichhk nichhk assigned nichhk and joshuayhwu and unassigned nichhk Jun 22, 2022
@joshuayhwu
Copy link
Contributor

joshuayhwu commented Jun 22, 2022

Replicated locally with requestTypeColors branch.

Exception on /_dash-update-component [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.7/site-packages/dash/dash.py", line 1078, in dispatch
    response.set_data(func(*args, outputs_list=outputs_list))
  File "/usr/local/lib/python3.7/site-packages/dash/dash.py", line 1009, in add_context
    output_value = func(*args, **kwargs)  # %% callback invoked %%
  File "/app/index.py", line 49, in display_page
    module = importlib.import_module(f"{DASH_FILES}.{last_part}")
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/app/dashboards/neighborhood_recent.py", line 70, in <module>
    labels=LABELS,
  File "/usr/local/lib/python3.7/site-packages/plotly/express/_chart_types.py", line 252, in line
    return make_figure(args=locals(), constructor=go.Scatter)
  File "/usr/local/lib/python3.7/site-packages/plotly/express/_core.py", line 1889, in make_figure
    for val in sorted_group_values[m.grouper]:
KeyError: 'typeName'

After checking the column names of the dataframe, the column name seems to exist but dataframe is empty given current date ranges. Not sure if it is related.

Empty DataFrame
Columns: [createdDate, typeName, srnumber]
...
KeyError: 'typeName'

Seems like order of argument matters. No clue yet - will take a look in the next few days.

EDIT: seems like the code doesn't handle the case when there is no data available. Once I set the date range further back, it ran smoothly. Couple things we need to do:

  • Take care of Dash Edge case when missing data
  • Diagnose data pipeline to ensure there is data flowing through API
  • PR for updated code

@joshuayhwu
Copy link
Contributor

Turns out it's unavoidable some councils have insufficient request for more recent requests (i.e. current week). Instead, I copied and pasted the query code and simply reload the query from 3 weeks ago if the dataframe for this week filters down to an empty table. This seems to work locally.

@joshuayhwu
Copy link
Contributor

Solution reccomened by Nich:

  • Added dummy data to empty tables within callback function in the event when there is no data. When there is no data, it'd look something like this:
    plotlyDash

  • Will have to wait for Piero's PR to merge before any upgrade. Let me know if this is viable solution.

P.S: There seems to be new data available again so dev website dashboards are working again

@nichhk
Copy link
Member Author

nichhk commented Jun 27, 2022

Thanks Josh! I was envisioning this graph still including the full legend, with all the request types, and that we would fill the dataframe with 0's for each day x request_type.

@joshuayhwu
Copy link
Contributor

plotlyDash3

A colorful alternative...

@joshuayhwu
Copy link
Contributor

plotlyDash4

Set to 0

@nichhk
Copy link
Member Author

nichhk commented Jul 1, 2022

LGTM! The pie chart is somewhat misleading, but we can think about that later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

2 participants