gov-uk-dashboards 23.1.0__tar.gz → 24.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gov_uk_dashboards-23.1.0/gov_uk_dashboards.egg-info → gov_uk_dashboards-24.1.0}/PKG-INFO +1 -2
- gov_uk_dashboards-24.1.0/gov_uk_dashboards/axes.py +22 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/__init__.py +0 -2
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/table.py +21 -100
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/figures/__init__.py +3 -2
- gov_uk_dashboards-24.1.0/gov_uk_dashboards/figures/chart_data.py +24 -0
- gov_uk_dashboards-24.1.0/gov_uk_dashboards/figures/line_chart.py +80 -0
- gov_uk_dashboards-24.1.0/gov_uk_dashboards/formatting/text_functions.py +11 -0
- gov_uk_dashboards-24.1.0/gov_uk_dashboards/lib/dap/get_dataframe_from_cds.py +109 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0/gov_uk_dashboards.egg-info}/PKG-INFO +1 -2
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards.egg-info/SOURCES.txt +1 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards.egg-info/requires.txt +0 -1
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/setup.py +1 -2
- gov_uk_dashboards-23.1.0/gov_uk_dashboards/axes.py +0 -21
- gov_uk_dashboards-23.1.0/gov_uk_dashboards/figures/chart_data.py +0 -24
- gov_uk_dashboards-23.1.0/gov_uk_dashboards/figures/line_chart.py +0 -80
- gov_uk_dashboards-23.1.0/gov_uk_dashboards/lib/dap/get_dataframe_from_cds.py +0 -109
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/LICENSE +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/MANIFEST.in +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/README.md +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/__init__.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/__init__.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/attach-event-to-dash.js +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/custom_map_style_functions.js +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/dashboard.css +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/download-map.js +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/fonts/bold-affa96571d-v2.woff +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/fonts/bold-b542beb274-v2.woff2 +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/fonts/light-94a07e06a1-v2.woff2 +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/fonts/light-f591b13f7d-v2.woff +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/get_assets_folder.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/govuk-frontend-3.14.0.min.js +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/DLUHC_WHITE_Master_AW_sm.png +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/MHCLG-favicon.png +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/MHCLG_favicon.png +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/dcms_coatofarms.png +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/dluhc_favicon.ico +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/gov_favicon.ico +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/govuk-crest.svg +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/hm-government-logo.png +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/mhclg_coat_of_arms.png +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/mhclg_white_no_background.png +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/oflog/MedianAbsolute.png +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/oflog/how_to_1_selecting_data.png +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/oflog/how_to_2_viewing_tabs.png +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/oflog/how_to_3_viewing_charts.png +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/oflog/how_to_4_viewing_trends.png +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/images/oflog/how_to_5_viewing_tables.png +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/index.html +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/mobile-nav.js +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/scripts.js +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/topojson/usa_110m.json +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/topojson/world_110m.json +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/colours.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/__init__.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/apply_and_reset_filters_buttons.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/banners.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/card.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/card_full_width.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/collapsible_panel.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/comparison_la_filter_button.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/context_banner.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/dashboard_container.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/details.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/download_button.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/filter_panel.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/footer.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/graph.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/header.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/heading.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/home_page_link_button.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/html_list.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/key_value_pair.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/main_content.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/navbar.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/no_data_message.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/notification_banner.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/paragraph.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/phase_banner.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/row_component.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/side_navbar.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/tooltip.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/tooltip_title.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/visualisation_commentary.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/visualisation_title.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/warning_text.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/helpers/__init__.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/helpers/display_chart_or_table_with_header.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/helpers/generate_dash_graph_from_figure.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/helpers/get_chart_for_download.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/helpers/plotting_helper_functions.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/helpers/update_layout_bgcolor_margin.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/leaflet/__init__.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/leaflet/leaflet_choropleth_map.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/plotly/__init__.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/plotly/captioned_figure.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/plotly/choropleth_map.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/plotly/enums.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/plotly/stacked_barchart.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/plotly/time_series_chart.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/constants.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/figures/enums/__init__.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/figures/enums/dash_patterns.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/figures/styles/__init__.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/figures/styles/line_style.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/formatting/__init__.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/formatting/human_readable.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/formatting/number_formatting.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/formatting/round_and_add_prefix_and_suffix.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/formatting/rounding.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/lib/__init__.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/lib/dap/__init__.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/lib/dap/dap_deployment.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/lib/datetime_functions/__init__.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/lib/datetime_functions/datetime_functions.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/lib/download_functions/__init__.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/lib/download_functions/convert_fig_to_image_and_download.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/lib/download_functions/download_csv_with_headers.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/lib/enable_basic_auth.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/lib/http_headers.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/lib/logging.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/symbols.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/template.html +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/template.py +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards.egg-info/dependency_links.txt +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards.egg-info/top_level.txt +0 -0
- {gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: gov_uk_dashboards
|
3
|
-
Version:
|
3
|
+
Version: 24.1.0
|
4
4
|
Summary: Provides access to functionality common to creating a data dashboard.
|
5
5
|
Author: Department for Levelling Up, Housing and Communities
|
6
6
|
Description-Content-Type: text/markdown
|
@@ -9,7 +9,6 @@ Requires-Dist: setuptools~=59.8
|
|
9
9
|
Requires-Dist: dash~=2.0
|
10
10
|
Requires-Dist: numpy>=1.22.0
|
11
11
|
Requires-Dist: dash_bootstrap_components~=1.1
|
12
|
-
Requires-Dist: pandas>=1.3
|
13
12
|
Requires-Dist: plotly~=5.5
|
14
13
|
Requires-Dist: flask-basicauth~=0.2.0
|
15
14
|
Dynamic: author
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"""Module containing functions related to graph axes.
|
2
|
+
|
3
|
+
Contains:
|
4
|
+
- calc_axis_range: Return a range for a column of a dataframe so the derived
|
5
|
+
axis is at the origin or the lowest negative value in the column, whichever
|
6
|
+
is lower.
|
7
|
+
"""
|
8
|
+
# from math import floor, ceil
|
9
|
+
|
10
|
+
# import pandas as pd
|
11
|
+
|
12
|
+
|
13
|
+
# def calc_axis_range(dataframe: pd.DataFrame, column: str) -> list:
|
14
|
+
# """Show origin on dashboard axis or negative value for numeric type column"""
|
15
|
+
# range_multiplier = 1.01
|
16
|
+
# axis_range = [
|
17
|
+
# floor(dataframe[[column]].min().iloc[0] * range_multiplier),
|
18
|
+
# ceil(dataframe[[column]].max().iloc[0] * range_multiplier),
|
19
|
+
# ]
|
20
|
+
# if axis_range[0] < 0:
|
21
|
+
# return axis_range
|
22
|
+
# return [0, axis_range[1]]
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/__init__.py
RENAMED
@@ -52,7 +52,6 @@ Contains:
|
|
52
52
|
- phase_banner_with_feedback: Return a phase banner with a feedback link,
|
53
53
|
which can be specified.
|
54
54
|
- row_component: Returns a horizontal row used to contain cards.
|
55
|
-
- table_from_dataframe: Return a html table created from a pandas DataFrame.
|
56
55
|
- tooltip_title: Return a tooltip component for explaining details.
|
57
56
|
- format_visualisation_commentary: Return paragraph styling commentary.
|
58
57
|
- format_visualisation_title: Return a default formatted title for a
|
@@ -84,7 +83,6 @@ from .paragraph import paragraph, ParagraphSizes
|
|
84
83
|
from .phase_banner import phase_banner_with_feedback
|
85
84
|
from .row_component import row_component
|
86
85
|
from .side_navbar import side_navbar
|
87
|
-
from .table import table_from_dataframe
|
88
86
|
from .tooltip_title import tooltip_title
|
89
87
|
from .visualisation_commentary import format_visualisation_commentary
|
90
88
|
from .visualisation_title import format_visualisation_title
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/table.py
RENAMED
@@ -1,109 +1,14 @@
|
|
1
1
|
"""Function for creating a table component from a dataframe"""
|
2
2
|
from typing import Optional
|
3
|
-
|
3
|
+
import polars as pl
|
4
4
|
from dash import html, dcc
|
5
5
|
from gov_uk_dashboards.components.dash.card import card
|
6
6
|
from gov_uk_dashboards.components.dash.paragraph import paragraph
|
7
|
-
|
8
|
-
# from gov_uk_dashboards.components.plotly.row_component import row_component
|
9
|
-
|
10
|
-
|
11
|
-
def table_from_dataframe(
|
12
|
-
dataframe: DataFrame,
|
13
|
-
title: Optional[str] = None,
|
14
|
-
first_column_is_header: bool = True,
|
15
|
-
title_is_subtitle: bool = False,
|
16
|
-
short_table: bool = True,
|
17
|
-
last_row_unbolded: bool = False,
|
18
|
-
format_column_headers_as_markdown: bool = False,
|
19
|
-
**table_properties,
|
20
|
-
): # pylint: disable=too-many-arguments
|
21
|
-
# pylint: disable=too-many-positional-arguments
|
22
|
-
"""
|
23
|
-
Displays a pandas DataFrame as a table formatted in the Gov.UK style
|
24
|
-
|
25
|
-
Part of the Gov.UK Design System:
|
26
|
-
https://design-system.service.gov.uk/components/table/
|
27
|
-
|
28
|
-
|
29
|
-
Args:
|
30
|
-
dataframe (DataFrame): Dataframe containing formatted data to display.
|
31
|
-
title (str, optional): Title to display above the table. Defaults to None.
|
32
|
-
first_column_is_header (bool, optional): Sets if the first column is a header column.
|
33
|
-
Defaults to True.
|
34
|
-
title_is_subtitle (bool, optional): Sets if the title should be displayed as a subtitle
|
35
|
-
or full title. Defaults to False.
|
36
|
-
short_table: (bool, optional): if False the header of the table will scroll with window.
|
37
|
-
last_row_unbolded: (bool, optional): Sets if the last row should not be bolded if
|
38
|
-
first_column_is_header is True. Defaults to False.
|
39
|
-
format_column_headers_as_markdown: (bool, optional): Sets if the column headers should
|
40
|
-
be formatted as markdown. Defaults to False.
|
41
|
-
**table_properties: Any additional arguments for the html.Table object,
|
42
|
-
such as setting a width or id.
|
43
|
-
|
44
|
-
Returns:
|
45
|
-
html.Table: The dash HTML object for the table.
|
46
|
-
"""
|
47
|
-
table_contents = []
|
48
|
-
|
49
|
-
if title:
|
50
|
-
table_contents.append(
|
51
|
-
html.Caption(
|
52
|
-
title,
|
53
|
-
className="govuk-table__caption govuk-table__caption--s"
|
54
|
-
if title_is_subtitle
|
55
|
-
else "govuk-table__caption govuk-table__caption--m",
|
56
|
-
)
|
57
|
-
)
|
58
|
-
|
59
|
-
table_contents.append(
|
60
|
-
html.Thead(
|
61
|
-
html.Tr(
|
62
|
-
[
|
63
|
-
html.Th(
|
64
|
-
dcc.Markdown(header),
|
65
|
-
scope="col",
|
66
|
-
className="govuk-table__header",
|
67
|
-
)
|
68
|
-
if format_column_headers_as_markdown
|
69
|
-
else html.Th(header, scope="col", className="govuk-table__header")
|
70
|
-
for header in dataframe.columns
|
71
|
-
],
|
72
|
-
className="govuk-table__row",
|
73
|
-
),
|
74
|
-
className="govuk-table__head-short" if short_table else "govuk-table__head",
|
75
|
-
)
|
76
|
-
)
|
77
|
-
|
78
|
-
last_row_index = len(dataframe) - 1 if last_row_unbolded else len(dataframe)
|
79
|
-
table_contents.append(
|
80
|
-
html.Tbody(
|
81
|
-
[
|
82
|
-
html.Tr(
|
83
|
-
[html.Th(row.iloc[0], scope="row", className="govuk-table__header")]
|
84
|
-
+ [html.Td(cell, className="govuk-table__cell") for cell in row[1:]]
|
85
|
-
)
|
86
|
-
if first_column_is_header and index != last_row_index
|
87
|
-
else html.Tr(
|
88
|
-
[html.Td(cell, className="govuk-table__cell") for cell in row]
|
89
|
-
)
|
90
|
-
for index, row in dataframe.iterrows()
|
91
|
-
],
|
92
|
-
className="govuk-table__body",
|
93
|
-
)
|
94
|
-
)
|
95
|
-
|
96
|
-
return html.Table(
|
97
|
-
table_contents,
|
98
|
-
className="govuk-table",
|
99
|
-
id="table",
|
100
|
-
role="table",
|
101
|
-
**table_properties,
|
102
|
-
)
|
7
|
+
from gov_uk_dashboards.formatting.text_functions import create_id_from_string
|
103
8
|
|
104
9
|
|
105
10
|
def table_from_polars_dataframe(
|
106
|
-
dataframe: DataFrame,
|
11
|
+
dataframe: pl.DataFrame,
|
107
12
|
title: Optional[str] = None,
|
108
13
|
subtitle: Optional[str] = None,
|
109
14
|
first_column_is_header: bool = True,
|
@@ -112,6 +17,7 @@ def table_from_polars_dataframe(
|
|
112
17
|
format_column_headers_as_markdown: bool = False,
|
113
18
|
sortable_headers: bool = False,
|
114
19
|
table_id: str = "table",
|
20
|
+
assign_ids_to_rows: bool = False,
|
115
21
|
table_footer: str = None,
|
116
22
|
column_widths: Optional[list[str]] = None,
|
117
23
|
columns_to_right_align: Optional[list[str]] = None,
|
@@ -144,6 +50,7 @@ def table_from_polars_dataframe(
|
|
144
50
|
sortable_headers: (bool, optional): Sets if the column headers should be sortable. Defaults
|
145
51
|
to False.
|
146
52
|
table_id: (str, optional): ID for the table Defaults to "table".
|
53
|
+
assign_ids_to_rows: (bool, optional): Adds id's to table rows when True. Defaults to False.
|
147
54
|
table_footer: (str, optional): Text to display underneath table as footer.
|
148
55
|
column_widths: (list[str], optional): Determines width of table columns. Format as a list,
|
149
56
|
"x%". List must be same length as dataframe columns. Defaults to None.
|
@@ -283,7 +190,14 @@ def table_from_polars_dataframe(
|
|
283
190
|
else {},
|
284
191
|
)
|
285
192
|
for cell, column_name in zip(row[1:], dataframe.columns[1:])
|
286
|
-
]
|
193
|
+
],
|
194
|
+
**(
|
195
|
+
{
|
196
|
+
"id": create_id_from_string(row[0])
|
197
|
+
if assign_ids_to_rows and create_id_from_string(row[0])
|
198
|
+
else {}
|
199
|
+
}
|
200
|
+
),
|
287
201
|
)
|
288
202
|
if first_column_is_header and index != last_row_index
|
289
203
|
else html.Tr(
|
@@ -296,7 +210,14 @@ def table_from_polars_dataframe(
|
|
296
210
|
else {},
|
297
211
|
)
|
298
212
|
for cell, column_name in zip(row, dataframe.columns)
|
299
|
-
]
|
213
|
+
],
|
214
|
+
**(
|
215
|
+
{
|
216
|
+
"id": create_id_from_string(row[0])
|
217
|
+
if assign_ids_to_rows and create_id_from_string(row[0])
|
218
|
+
else {}
|
219
|
+
}
|
220
|
+
),
|
300
221
|
)
|
301
222
|
)
|
302
223
|
for index, row in enumerate(dataframe.rows())
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"""ChartData dataclass"""
|
2
|
+
# from dataclasses import dataclass
|
3
|
+
# from typing import Optional
|
4
|
+
|
5
|
+
# import pandas as pd
|
6
|
+
|
7
|
+
|
8
|
+
# @dataclass
|
9
|
+
# class ChartData:
|
10
|
+
# """
|
11
|
+
# Dataclass containing standard information useful for plotting charts.
|
12
|
+
|
13
|
+
# Attributes:
|
14
|
+
# dataframe (pd.DataFrame): The dataframe containing the data for the chart.
|
15
|
+
# x_column (str): The label of the column containing the x axis values.
|
16
|
+
# y_column (str): The label of the column containing the y axis values.
|
17
|
+
# category_column (str, optional): If there are multiple categories in the data,
|
18
|
+
# this column gives the value to categorize them. Defaults to None.
|
19
|
+
# """
|
20
|
+
|
21
|
+
# dataframe: pd.DataFrame
|
22
|
+
# x_column: str
|
23
|
+
# y_column: str
|
24
|
+
# category_column: Optional[str] = None
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# """Line chart function"""
|
2
|
+
# from typing import Optional
|
3
|
+
# import plotly.express as px
|
4
|
+
# from gov_uk_dashboards.axes import calc_axis_range
|
5
|
+
# from gov_uk_dashboards.colours import ONSAccessibleColours
|
6
|
+
# from .styles import LineStyle
|
7
|
+
# from .chart_data import ChartData
|
8
|
+
|
9
|
+
|
10
|
+
# def line_chart(
|
11
|
+
# data: ChartData,
|
12
|
+
# title: str,
|
13
|
+
# markers: bool = False,
|
14
|
+
# line_styles: Optional[dict[str, LineStyle]] = None,
|
15
|
+
# **px_line_kwargs,
|
16
|
+
# ):
|
17
|
+
# """
|
18
|
+
# Create and return a plotly express line chart with standard formatting.
|
19
|
+
|
20
|
+
# Dataframe should be sorted so x axis is in the correct order for plotting.
|
21
|
+
|
22
|
+
# If no style information provided, lines will be plotted as solid lines
|
23
|
+
# using the ONSAcessibleColours enum for their colours.
|
24
|
+
|
25
|
+
# Args:
|
26
|
+
# data (ChartData): Data for the chart.
|
27
|
+
# title (str): Title to be shown above the chart.
|
28
|
+
# markers (bool, optional): Whether markers should be plotted for each point.
|
29
|
+
# Defaults to False.
|
30
|
+
# line_styles (dict[str, LineStyle], optional): A dictionary with keys that match
|
31
|
+
# the categories in the category column (if supplied), and values that are
|
32
|
+
# LineStyle data objects to set out the style of the corresponding line.
|
33
|
+
# Defaults to None.
|
34
|
+
# **px_line_kwargs: Any other keyword arguments to pass to the plotly express
|
35
|
+
# line graph function.
|
36
|
+
|
37
|
+
# Returns:
|
38
|
+
# plotly.Figure: The generated line chart figure object.
|
39
|
+
# """
|
40
|
+
# color_discrete_map = None
|
41
|
+
# line_dash_map = None
|
42
|
+
# labels = None
|
43
|
+
# if line_styles:
|
44
|
+
# color_discrete_map = {
|
45
|
+
# category: line_style.color for category, line_style in line_styles.items()
|
46
|
+
# }
|
47
|
+
# line_dash_map = {
|
48
|
+
# category: line_style.dash_pattern
|
49
|
+
# for category, line_style in line_styles.items()
|
50
|
+
# }
|
51
|
+
# # If line dashes are set, plotly express automatically appends the name of the dash style
|
52
|
+
# # to the label in the legend/hover data.
|
53
|
+
# # As this is normally not desired, labels are set manually to override this.
|
54
|
+
# labels = {category: category for category in line_styles}
|
55
|
+
|
56
|
+
# linechart = px.line(
|
57
|
+
# data.dataframe,
|
58
|
+
# x=data.x_column,
|
59
|
+
# y=data.y_column,
|
60
|
+
# range_y=calc_axis_range(data.dataframe, data.y_column),
|
61
|
+
# color_discrete_map=color_discrete_map,
|
62
|
+
# line_dash_map=line_dash_map,
|
63
|
+
# line_dash=data.category_column,
|
64
|
+
# color=data.category_column,
|
65
|
+
# labels=labels,
|
66
|
+
# markers=markers,
|
67
|
+
# color_discrete_sequence=[colour.value for colour in ONSAccessibleColours]
|
68
|
+
# if not line_styles
|
69
|
+
# else None,
|
70
|
+
# **px_line_kwargs,
|
71
|
+
# )
|
72
|
+
|
73
|
+
# linechart.update_layout(
|
74
|
+
# title=title,
|
75
|
+
# paper_bgcolor="rgba(0,0,0,0)",
|
76
|
+
# plot_bgcolor="rgba(0,0,0,0)",
|
77
|
+
# xaxis_type="category",
|
78
|
+
# )
|
79
|
+
|
80
|
+
# return linechart
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"""Functions to format text"""
|
2
|
+
|
3
|
+
import re
|
4
|
+
|
5
|
+
|
6
|
+
def create_id_from_string(string):
|
7
|
+
"""Function to create an id from a string. Remove non alphanumeric characters and replaces
|
8
|
+
spaces with dashes"""
|
9
|
+
if string is None:
|
10
|
+
return ""
|
11
|
+
return re.sub(r"[^a-z0-9]+", "-", string.lower()).strip("-")
|
@@ -0,0 +1,109 @@
|
|
1
|
+
""" Returns a dataframe after connecting to CDS, otherwise uses a csv already saved in the file"""
|
2
|
+
# import os
|
3
|
+
# import json
|
4
|
+
# import pyodbc
|
5
|
+
# import boto3
|
6
|
+
|
7
|
+
|
8
|
+
# def get_data_from_cds_or_fallback_to_csv(
|
9
|
+
# cds_sql_query: str, csv_path: str, secret_name: str, cds_server_name: str
|
10
|
+
# ) -> pd.DataFrame:
|
11
|
+
# """Tries to return dataframe from CDS first via Pydash credentials,
|
12
|
+
# otherwise via Amazon WorkSpaces,
|
13
|
+
# otherwise via a file from folder.
|
14
|
+
# Inputs:
|
15
|
+
# cds_sql_query(str): SQL query string
|
16
|
+
# csv_path(str): Filepath for location of csv to fallback to
|
17
|
+
# secret_name(str): AWS Secrets Manager, secret name containing CDS credentials.
|
18
|
+
# cds_server_name(str): CDS Server name used in connection string
|
19
|
+
# Returns:
|
20
|
+
# pd.DataFrame
|
21
|
+
# """
|
22
|
+
# if (
|
23
|
+
# "DATA_FOLDER_LOCATION" in os.environ
|
24
|
+
# and os.environ["DATA_FOLDER_LOCATION"] == "tests/"
|
25
|
+
# ) or ("STAGE" in os.environ and os.environ["STAGE"] == "testing"):
|
26
|
+
# return pd.read_csv(csv_path)
|
27
|
+
|
28
|
+
# try:
|
29
|
+
# conn = pyodbc.connect(
|
30
|
+
# _get_pydash_connection_string(secret_name, cds_server_name)
|
31
|
+
# )
|
32
|
+
# print("Dataframe has been loaded from CDS using Pydash credentials")
|
33
|
+
|
34
|
+
# return pd.read_sql_query(
|
35
|
+
# cds_sql_query,
|
36
|
+
# conn,
|
37
|
+
# )
|
38
|
+
|
39
|
+
# except Exception as credential_error: # pylint: disable=broad-except
|
40
|
+
# try:
|
41
|
+
# print(
|
42
|
+
# "Failed to load dataframe using Pydash credentials: ", credential_error
|
43
|
+
# )
|
44
|
+
# conn = pyodbc.connect(
|
45
|
+
# "Driver={SQL Server};"
|
46
|
+
# f"Server={cds_server_name};"
|
47
|
+
# "Database=Dashboards;"
|
48
|
+
# "Trusted_Connection=yes;"
|
49
|
+
# )
|
50
|
+
# print(
|
51
|
+
# "Dataframe has been loaded from CDS using Windows login authentication"
|
52
|
+
# )
|
53
|
+
|
54
|
+
# return pd.read_sql_query(
|
55
|
+
# cds_sql_query,
|
56
|
+
# conn,
|
57
|
+
# )
|
58
|
+
|
59
|
+
# except pyodbc.Error as conn_error_except:
|
60
|
+
# print(
|
61
|
+
# "Failed to load dataframe using Windows login authentication: ",
|
62
|
+
# conn_error_except,
|
63
|
+
# )
|
64
|
+
# print("Dataframe has been loaded from CSV")
|
65
|
+
# return pd.read_csv(csv_path)
|
66
|
+
|
67
|
+
|
68
|
+
# def _get_pydash_connection_string(secret_name: str, cds_server_name: str):
|
69
|
+
# """
|
70
|
+
# Pydash aka DAP Hosting requires username and password
|
71
|
+
# Inputs:
|
72
|
+
# secret_name(str): AWS Secrets Manager, secret name containing CDS credentials.
|
73
|
+
# cds_server_name(str): CDS Server name used in connection string
|
74
|
+
# """
|
75
|
+
# credentials = _pydash_sql_credentials(secret_name)
|
76
|
+
# conn_string_dap = (
|
77
|
+
# "Driver={/usr/lib/libmsodbcsql-18.so};"
|
78
|
+
# f"Server={cds_server_name};"
|
79
|
+
# "TrustServerCertificate=yes;"
|
80
|
+
# "Database=Dashboards;"
|
81
|
+
# )
|
82
|
+
# return (
|
83
|
+
# f"{conn_string_dap}UID={credentials['username']};PWD={credentials['password']};"
|
84
|
+
# )
|
85
|
+
|
86
|
+
|
87
|
+
# def _pydash_sql_credentials(secret_name: str):
|
88
|
+
# """
|
89
|
+
# Logging into CDS from Pydash requires user name and password.
|
90
|
+
# This method will return a dictionary containing the keys "username" and "password".
|
91
|
+
# Raises `botocore.exceptions.ClientError` if no credentials could be obtained
|
92
|
+
# Inputs:
|
93
|
+
# secret_name(str): AWS Secrets Manager, secret name containing CDS credentials.
|
94
|
+
# Returns:
|
95
|
+
# dict: a dictionary containing the keys "username" and "password"
|
96
|
+
# """
|
97
|
+
# region_name = "eu-west-1"
|
98
|
+
# # Create a Secrets Manager client
|
99
|
+
# session = boto3.session.Session()
|
100
|
+
# client = session.client(service_name="secretsmanager", region_name=region_name)
|
101
|
+
# # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/secretsmanager
|
102
|
+
# .html#SecretsManager.Client.get_secret_value
|
103
|
+
|
104
|
+
# get_secret_value_response = client.get_secret_value(SecretId=secret_name)
|
105
|
+
|
106
|
+
# secret = get_secret_value_response["SecretString"]
|
107
|
+
|
108
|
+
# credentials = json.loads(secret)
|
109
|
+
# return credentials
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: gov_uk_dashboards
|
3
|
-
Version:
|
3
|
+
Version: 24.1.0
|
4
4
|
Summary: Provides access to functionality common to creating a data dashboard.
|
5
5
|
Author: Department for Levelling Up, Housing and Communities
|
6
6
|
Description-Content-Type: text/markdown
|
@@ -9,7 +9,6 @@ Requires-Dist: setuptools~=59.8
|
|
9
9
|
Requires-Dist: dash~=2.0
|
10
10
|
Requires-Dist: numpy>=1.22.0
|
11
11
|
Requires-Dist: dash_bootstrap_components~=1.1
|
12
|
-
Requires-Dist: pandas>=1.3
|
13
12
|
Requires-Dist: plotly~=5.5
|
14
13
|
Requires-Dist: flask-basicauth~=0.2.0
|
15
14
|
Dynamic: author
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards.egg-info/SOURCES.txt
RENAMED
@@ -106,6 +106,7 @@ gov_uk_dashboards/formatting/human_readable.py
|
|
106
106
|
gov_uk_dashboards/formatting/number_formatting.py
|
107
107
|
gov_uk_dashboards/formatting/round_and_add_prefix_and_suffix.py
|
108
108
|
gov_uk_dashboards/formatting/rounding.py
|
109
|
+
gov_uk_dashboards/formatting/text_functions.py
|
109
110
|
gov_uk_dashboards/lib/__init__.py
|
110
111
|
gov_uk_dashboards/lib/enable_basic_auth.py
|
111
112
|
gov_uk_dashboards/lib/http_headers.py
|
@@ -10,7 +10,7 @@ setup(
|
|
10
10
|
author="Department for Levelling Up, Housing and Communities",
|
11
11
|
description="Provides access to functionality common to creating a data dashboard.",
|
12
12
|
name="gov_uk_dashboards",
|
13
|
-
version="
|
13
|
+
version="24.1.0",
|
14
14
|
long_description=long_description,
|
15
15
|
long_description_content_type="text/markdown",
|
16
16
|
packages=find_packages(),
|
@@ -19,7 +19,6 @@ setup(
|
|
19
19
|
"dash~=2.0",
|
20
20
|
"numpy>=1.22.0",
|
21
21
|
"dash_bootstrap_components~=1.1",
|
22
|
-
"pandas>=1.3",
|
23
22
|
"plotly~=5.5",
|
24
23
|
"flask-basicauth~=0.2.0",
|
25
24
|
],
|
@@ -1,21 +0,0 @@
|
|
1
|
-
"""Module containing functions related to graph axes.
|
2
|
-
|
3
|
-
Contains:
|
4
|
-
- calc_axis_range: Return a range for a column of a dataframe so the derived
|
5
|
-
axis is at the origin or the lowest negative value in the column, whichever
|
6
|
-
is lower.
|
7
|
-
"""
|
8
|
-
from math import floor, ceil
|
9
|
-
import pandas as pd
|
10
|
-
|
11
|
-
|
12
|
-
def calc_axis_range(dataframe: pd.DataFrame, column: str) -> list:
|
13
|
-
"""Show origin on dashboard axis or negative value for numeric type column"""
|
14
|
-
range_multiplier = 1.01
|
15
|
-
axis_range = [
|
16
|
-
floor(dataframe[[column]].min().iloc[0] * range_multiplier),
|
17
|
-
ceil(dataframe[[column]].max().iloc[0] * range_multiplier),
|
18
|
-
]
|
19
|
-
if axis_range[0] < 0:
|
20
|
-
return axis_range
|
21
|
-
return [0, axis_range[1]]
|
@@ -1,24 +0,0 @@
|
|
1
|
-
"""ChartData dataclass"""
|
2
|
-
from dataclasses import dataclass
|
3
|
-
from typing import Optional
|
4
|
-
|
5
|
-
import pandas as pd
|
6
|
-
|
7
|
-
|
8
|
-
@dataclass
|
9
|
-
class ChartData:
|
10
|
-
"""
|
11
|
-
Dataclass containing standard information useful for plotting charts.
|
12
|
-
|
13
|
-
Attributes:
|
14
|
-
dataframe (pd.DataFrame): The dataframe containing the data for the chart.
|
15
|
-
x_column (str): The label of the column containing the x axis values.
|
16
|
-
y_column (str): The label of the column containing the y axis values.
|
17
|
-
category_column (str, optional): If there are multiple categories in the data,
|
18
|
-
this column gives the value to categorize them. Defaults to None.
|
19
|
-
"""
|
20
|
-
|
21
|
-
dataframe: pd.DataFrame
|
22
|
-
x_column: str
|
23
|
-
y_column: str
|
24
|
-
category_column: Optional[str] = None
|
@@ -1,80 +0,0 @@
|
|
1
|
-
"""Line chart function"""
|
2
|
-
from typing import Optional
|
3
|
-
import plotly.express as px
|
4
|
-
from gov_uk_dashboards.axes import calc_axis_range
|
5
|
-
from gov_uk_dashboards.colours import ONSAccessibleColours
|
6
|
-
from .styles import LineStyle
|
7
|
-
from .chart_data import ChartData
|
8
|
-
|
9
|
-
|
10
|
-
def line_chart(
|
11
|
-
data: ChartData,
|
12
|
-
title: str,
|
13
|
-
markers: bool = False,
|
14
|
-
line_styles: Optional[dict[str, LineStyle]] = None,
|
15
|
-
**px_line_kwargs,
|
16
|
-
):
|
17
|
-
"""
|
18
|
-
Create and return a plotly express line chart with standard formatting.
|
19
|
-
|
20
|
-
Dataframe should be sorted so x axis is in the correct order for plotting.
|
21
|
-
|
22
|
-
If no style information provided, lines will be plotted as solid lines
|
23
|
-
using the ONSAcessibleColours enum for their colours.
|
24
|
-
|
25
|
-
Args:
|
26
|
-
data (ChartData): Data for the chart.
|
27
|
-
title (str): Title to be shown above the chart.
|
28
|
-
markers (bool, optional): Whether markers should be plotted for each point.
|
29
|
-
Defaults to False.
|
30
|
-
line_styles (dict[str, LineStyle], optional): A dictionary with keys that match
|
31
|
-
the categories in the category column (if supplied), and values that are
|
32
|
-
LineStyle data objects to set out the style of the corresponding line.
|
33
|
-
Defaults to None.
|
34
|
-
**px_line_kwargs: Any other keyword arguments to pass to the plotly express
|
35
|
-
line graph function.
|
36
|
-
|
37
|
-
Returns:
|
38
|
-
plotly.Figure: The generated line chart figure object.
|
39
|
-
"""
|
40
|
-
color_discrete_map = None
|
41
|
-
line_dash_map = None
|
42
|
-
labels = None
|
43
|
-
if line_styles:
|
44
|
-
color_discrete_map = {
|
45
|
-
category: line_style.color for category, line_style in line_styles.items()
|
46
|
-
}
|
47
|
-
line_dash_map = {
|
48
|
-
category: line_style.dash_pattern
|
49
|
-
for category, line_style in line_styles.items()
|
50
|
-
}
|
51
|
-
# If line dashes are set, plotly express automatically appends the name of the dash style
|
52
|
-
# to the label in the legend/hover data.
|
53
|
-
# As this is normally not desired, labels are set manually to override this.
|
54
|
-
labels = {category: category for category in line_styles}
|
55
|
-
|
56
|
-
linechart = px.line(
|
57
|
-
data.dataframe,
|
58
|
-
x=data.x_column,
|
59
|
-
y=data.y_column,
|
60
|
-
range_y=calc_axis_range(data.dataframe, data.y_column),
|
61
|
-
color_discrete_map=color_discrete_map,
|
62
|
-
line_dash_map=line_dash_map,
|
63
|
-
line_dash=data.category_column,
|
64
|
-
color=data.category_column,
|
65
|
-
labels=labels,
|
66
|
-
markers=markers,
|
67
|
-
color_discrete_sequence=[colour.value for colour in ONSAccessibleColours]
|
68
|
-
if not line_styles
|
69
|
-
else None,
|
70
|
-
**px_line_kwargs,
|
71
|
-
)
|
72
|
-
|
73
|
-
linechart.update_layout(
|
74
|
-
title=title,
|
75
|
-
paper_bgcolor="rgba(0,0,0,0)",
|
76
|
-
plot_bgcolor="rgba(0,0,0,0)",
|
77
|
-
xaxis_type="category",
|
78
|
-
)
|
79
|
-
|
80
|
-
return linechart
|
@@ -1,109 +0,0 @@
|
|
1
|
-
""" Returns a dataframe after connecting to CDS, otherwise uses a csv already saved in the file"""
|
2
|
-
import os
|
3
|
-
import json
|
4
|
-
import pandas as pd
|
5
|
-
import pyodbc
|
6
|
-
import boto3
|
7
|
-
|
8
|
-
|
9
|
-
def get_data_from_cds_or_fallback_to_csv(
|
10
|
-
cds_sql_query: str, csv_path: str, secret_name: str, cds_server_name: str
|
11
|
-
) -> pd.DataFrame:
|
12
|
-
"""Tries to return dataframe from CDS first via Pydash credentials,
|
13
|
-
otherwise via Amazon WorkSpaces,
|
14
|
-
otherwise via a file from folder.
|
15
|
-
Inputs:
|
16
|
-
cds_sql_query(str): SQL query string
|
17
|
-
csv_path(str): Filepath for location of csv to fallback to
|
18
|
-
secret_name(str): AWS Secrets Manager, secret name containing CDS credentials.
|
19
|
-
cds_server_name(str): CDS Server name used in connection string
|
20
|
-
Returns:
|
21
|
-
pd.DataFrame
|
22
|
-
"""
|
23
|
-
if (
|
24
|
-
"DATA_FOLDER_LOCATION" in os.environ
|
25
|
-
and os.environ["DATA_FOLDER_LOCATION"] == "tests/"
|
26
|
-
) or ("STAGE" in os.environ and os.environ["STAGE"] == "testing"):
|
27
|
-
return pd.read_csv(csv_path)
|
28
|
-
|
29
|
-
try:
|
30
|
-
conn = pyodbc.connect(
|
31
|
-
_get_pydash_connection_string(secret_name, cds_server_name)
|
32
|
-
)
|
33
|
-
print("Dataframe has been loaded from CDS using Pydash credentials")
|
34
|
-
|
35
|
-
return pd.read_sql_query(
|
36
|
-
cds_sql_query,
|
37
|
-
conn,
|
38
|
-
)
|
39
|
-
|
40
|
-
except Exception as credential_error: # pylint: disable=broad-except
|
41
|
-
try:
|
42
|
-
print(
|
43
|
-
"Failed to load dataframe using Pydash credentials: ", credential_error
|
44
|
-
)
|
45
|
-
conn = pyodbc.connect(
|
46
|
-
"Driver={SQL Server};"
|
47
|
-
f"Server={cds_server_name};"
|
48
|
-
"Database=Dashboards;"
|
49
|
-
"Trusted_Connection=yes;"
|
50
|
-
)
|
51
|
-
print(
|
52
|
-
"Dataframe has been loaded from CDS using Windows login authentication"
|
53
|
-
)
|
54
|
-
|
55
|
-
return pd.read_sql_query(
|
56
|
-
cds_sql_query,
|
57
|
-
conn,
|
58
|
-
)
|
59
|
-
|
60
|
-
except pyodbc.Error as conn_error_except:
|
61
|
-
print(
|
62
|
-
"Failed to load dataframe using Windows login authentication: ",
|
63
|
-
conn_error_except,
|
64
|
-
)
|
65
|
-
print("Dataframe has been loaded from CSV")
|
66
|
-
return pd.read_csv(csv_path)
|
67
|
-
|
68
|
-
|
69
|
-
def _get_pydash_connection_string(secret_name: str, cds_server_name: str):
|
70
|
-
"""
|
71
|
-
Pydash aka DAP Hosting requires username and password
|
72
|
-
Inputs:
|
73
|
-
secret_name(str): AWS Secrets Manager, secret name containing CDS credentials.
|
74
|
-
cds_server_name(str): CDS Server name used in connection string
|
75
|
-
"""
|
76
|
-
credentials = _pydash_sql_credentials(secret_name)
|
77
|
-
conn_string_dap = (
|
78
|
-
"Driver={/usr/lib/libmsodbcsql-18.so};"
|
79
|
-
f"Server={cds_server_name};"
|
80
|
-
"TrustServerCertificate=yes;"
|
81
|
-
"Database=Dashboards;"
|
82
|
-
)
|
83
|
-
return (
|
84
|
-
f"{conn_string_dap}UID={credentials['username']};PWD={credentials['password']};"
|
85
|
-
)
|
86
|
-
|
87
|
-
|
88
|
-
def _pydash_sql_credentials(secret_name: str):
|
89
|
-
"""
|
90
|
-
Logging into CDS from Pydash requires user name and password.
|
91
|
-
This method will return a dictionary containing the keys "username" and "password".
|
92
|
-
Raises `botocore.exceptions.ClientError` if no credentials could be obtained
|
93
|
-
Inputs:
|
94
|
-
secret_name(str): AWS Secrets Manager, secret name containing CDS credentials.
|
95
|
-
Returns:
|
96
|
-
dict: a dictionary containing the keys "username" and "password"
|
97
|
-
"""
|
98
|
-
region_name = "eu-west-1"
|
99
|
-
# Create a Secrets Manager client
|
100
|
-
session = boto3.session.Session()
|
101
|
-
client = session.client(service_name="secretsmanager", region_name=region_name)
|
102
|
-
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/secretsmanager.html#SecretsManager.Client.get_secret_value
|
103
|
-
|
104
|
-
get_secret_value_response = client.get_secret_value(SecretId=secret_name)
|
105
|
-
|
106
|
-
secret = get_secret_value_response["SecretString"]
|
107
|
-
|
108
|
-
credentials = json.loads(secret)
|
109
|
-
return credentials
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/dashboard.css
RENAMED
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/download-map.js
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/get_assets_folder.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/assets/mobile-nav.js
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/__init__.py
RENAMED
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/banners.py
RENAMED
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/card.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/details.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/footer.py
RENAMED
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/graph.py
RENAMED
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/header.py
RENAMED
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/heading.py
RENAMED
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/html_list.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/navbar.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/paragraph.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/dash/tooltip.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/components/plotly/enums.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/figures/enums/__init__.py
RENAMED
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/figures/styles/__init__.py
RENAMED
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/figures/styles/line_style.py
RENAMED
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/formatting/__init__.py
RENAMED
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/formatting/human_readable.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/formatting/rounding.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/lib/dap/dap_deployment.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards/lib/enable_basic_auth.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{gov_uk_dashboards-23.1.0 → gov_uk_dashboards-24.1.0}/gov_uk_dashboards.egg-info/top_level.txt
RENAMED
File without changes
|
File without changes
|