C-Dash: Add search in tests
[csit.git] / csit.infra.dash / app / cdash / trending / trending.py
1 # Copyright (c) 2024 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 """Instantiate the Trending Dash application.
15 """
16 import dash
17 import pandas as pd
18
19 from ..utils.constants import Constants as C
20 from .layout import Layout
21
22
23 def init_trending(
24         server,
25         data_trending: pd.DataFrame
26     ) -> dash.Dash:
27     """Create a Plotly Dash dashboard.
28
29     :param server: Flask server.
30     :type server: Flask
31     :returns: Dash app server.
32     :rtype: Dash
33     """
34
35     dash_app = dash.Dash(
36         server=server,
37         routes_pathname_prefix=C.TREND_ROUTES_PATHNAME_PREFIX,
38         external_stylesheets=C.EXTERNAL_STYLESHEETS,
39         title=C.TREND_TITLE
40     )
41
42     layout = Layout(
43         app=dash_app,
44         data_trending=data_trending,
45         html_layout_file=C.HTML_LAYOUT_FILE,
46         graph_layout_file=C.TREND_GRAPH_LAYOUT_FILE,
47         tooltip_file=C.TOOLTIP_FILE
48     )
49     dash_app.index_string = layout.html_layout
50     dash_app.layout = layout.add_content()
51
52     return dash_app.server