Skip to content

Commit

Permalink
✨ Do not load reporting plot during loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
dalonsoa committed Oct 21, 2024
1 parent c106d5d commit 433f693
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
50 changes: 40 additions & 10 deletions measurement/dash_apps/data_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,36 @@
@app.callback(
Output("data_report_graph", "figure"),
[
Input("temporality_drop", "value"),
Input("station_drop", "value"),
Input("variable_drop", "value"),
Input("date_range_picker", "start_date"),
Input("date_range_picker", "end_date"),
Input("data_report_graph", "relayoutData"),
Input("display_button", "n_clicks"),
],
[
State("temporality_drop", "value"),
State("station_drop", "value"),
State("variable_drop", "value"),
State("date_range_picker", "start_date"),
State("date_range_picker", "end_date"),
State("data_report_graph", "figure"),
],
)
def update_graph(
relayout_data: dict,
n_clicks: int,
temporality: str,
station: str,
variable: str,
start_time: str,
end_time: str,
relayout_data: dict,
figure: go.Figure,
callback_context,
) -> go.Figure:
ctx = callback_context
triggered_id = ctx.triggered[0]["prop_id"].split(".")[0] if ctx.triggered else ""

if not n_clicks:
# After the first load, n_clicks is always > 0, so zooming works
return figure

# This is cached, so it's not a big deal to call it multiple times
data = get_report_data_from_db(
station=station,
Expand Down Expand Up @@ -215,17 +225,37 @@ def download_csv_report(
Output("data_alert_div", "children"),
Output("csv_div", "children"),
],
Input("data_report_graph", "figure"),
[
Input("temporality_drop", "value"),
Input("station_drop", "value"),
Input("variable_drop", "value"),
Input("date_range_picker", "start_date"),
Input("date_range_picker", "end_date"),
],
State("data_report_graph", "figure"),
)
def update_alert(figure):
def update_alert(
temporality: str,
station: str,
variable: str,
start_time: str,
end_time: str,
figure: go.Figure,
):
if figure["layout"]["title"]["text"] == "Data not found":
alert = dbc.Alert(
"No data was found with the selected criteria", color="warning"
)
return [alert], []
else:
button = html.Button("Download CSV", id="csv_button")
return [], [button]
download = html.Button("Download CSV", id="csv_button")
display = html.Button(
"Display data",
id="display_button",
style={"margin-left": "10px"},
n_clicks=0,
)
return [], [download, display]


@app.callback(
Expand Down
2 changes: 1 addition & 1 deletion measurement/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def save_report_data(data: pd.DataFrame) -> None:
)


@lru_cache
@lru_cache(1)
def get_report_data_from_db(
station: str,
variable: str,
Expand Down

0 comments on commit 433f693

Please sign in to comment.