示例#1
0
def Classification_Options(options):
    """
    Generate the layout of the dashboard.

    Args:
        options (list(dict)): Available datasets as options for `dcc.Dropdown`.

    Returns:
        A Dash element or list of elements.
    """

    return html.Div(children=[
        # Choose a dataset
        html.Div(create_dropdown("Available datasets", options,
                                 multi=False, id="dataset_choice_classification"),
                 className="horizontal_dropdowns"),

        # Choose an algorithm
        html.Div(create_dropdown("Choose algorithm type", options=[
            {'label': 'Logistic Regression', 'value': 'logr'},
            {'label': 'XGBoost', 'value': 'xgb'},
        ], multi=False, id="algo_choice_classification"),
                 className="horizontal_dropdowns"),

        ## Two empty divs to be filled by callbacks
        # Available choices for fitting
        html.Div(id="variable_choices_classification"),

        # The results
        html.Div(id="training_results_classification"),

        dcc.Graph(id="classification_results")
    ])
def inspect_node(selected, user_id, elems):

    if selected is None or "parent" not in selected:
        # No need to show info for parent nodes as
        # they are there just for show
        raise PreventUpdate()

    # Defaults
    multi = False
    dataset_choice = None

    if len(selected):
        func = node_options[selected["node_type"]]["func"]
        arguments = list(func.modifiable_params.keys())

        # func is a SKLEARN-like class
        if isinstance(func(), pipeline_classes.GenericInput):
            arguments = ["dataset"]

        options = [{"label": arg, "value": arg} for arg in arguments]

    if isinstance(func(), pipeline_classes.FeatureMaker):
        # 1) Select appropriate elements and make the graph
        # 2) Create pipelines
        # 3) Iterate over them to find the one with FeatureMaker node
        # 4) Iterate over that again to find its input node

        input_node = pipeline_creator.find_input_node(elems)

        try:
            dataset_choice = input_node.dataset
        except AttributeError:
            return [
                html.H4("Something went wrong with the input"),

                # for debugging a global callback
                *create_dropdown("", [],
                                 id="modify_option_dropdown",
                                 style={"display": "none"}),
                *debugger_layout,
            ]

        df = get_data(dataset_choice, user_id)

        # Truncate labels so they don't fill the whole dropdown
        options = [{'label': col[:35], 'value': col} for col in df.columns]
        multi = True

    return [
        html.Div([
            *create_dropdown(
                "Options", options, id="modify_option_dropdown", multi=multi),
            html.Div([], id="other_menus"),

            # here only to debug the modify_graph callback
            *debugger_layout,
        ]),
    ]
示例#3
0
def Pipeline_Options(options, user_id):
    """
    Generate the layout of the dashboard.

    Args:
        options (list(dict)): Available datasets as options for `dcc.Dropdown`.

    Returns:
        A Dash element or list of elements.
    """

    if user_id.startswith("python_generated_ssid"):
        # Trim id
        user_id = user_id.split("-")[-1]

    available_pipelines = {
        k.decode(): r.get(k)
        for k in r.keys(f'{user_id}_pipeline_*')
    }

    return html.Div(children=[
        # Dataset is defined in the ModelBuilder

        # Choose an algorithm
        html.Div(create_dropdown("Choose algorithm type",
                                 options=[{
                                     'label': f'Pipeline --> {pipe_name}',
                                     'value': pipe_name
                                 } for pipe_name in available_pipelines],
                                 multi=False,
                                 id="algo_choice_pipeline"),
                 className="horizontal_dropdowns"),

        # Available choices for fitting
        html.Div(
            id="variable_choices_pipeline",
            children=[
                # Debuggers
                html.Button("Fit model",
                            id="fit_model",
                            n_clicks=0,
                            style={"display": "none"}),
                html.Div(
                    create_dropdown("", [],
                                    multi=True,
                                    id="xvars_pipeline",
                                    style={"display": "none"})),
                html.Div(
                    create_dropdown("", [],
                                    multi=True,
                                    id="yvars_pipeline",
                                    style={"display": "none"})),
            ]),

        # The results
        html.Div(id="training_results_pipeline"),
    ])
示例#4
0
def render_choices(problem_type, dataset_choice):
    """
    Create a menu for fitting options, depending of the problem type. It \
    returns dropdowns with algorithm choices.

    Args:
        problem_type (str): One of: regression, classification, clustering.
        dataset_choice (str): Name of the dataset.

    Returns:
        A Dash element or list of elements.
    """

    if problem_type is None or dataset_choice is None:
        raise PreventUpdate()

    # Load the schema for the dataset
    df_schema = get_data_schema(dataset_choice, redis_conn)["types"]

    # From the schema take the dataset's column names
    var_options = [
        {"label": col, "value": col}
        for col in df_schema.keys()
    ]

    disabled_y = False
    algo_options = None

    # Depending on the problem type, show the available algorithms
    if problem_type in ["regression", "classification", "clustering"]:
        disabled_y = False
        algo_options = [
            {'label': estimator["label"], 'value': estimator["node_type"]}
            for estimator in all_classes
            if (estimator["parent"] == "models" and
                estimator["problem"] == problem_type)
        ]

        if problem_type == "clustering":
            disabled_y = True

    return html.Div([
        html.Div(create_dropdown("Choose algorithm type",
                                 options=algo_options,
                                 multi=False, id="algo_choice")),

        html.Div(create_dropdown("Choose variable(s) X",
                                 options=var_options,
                                 multi=True, id="xvars")),

        html.Div(create_dropdown("Choose target variable Y",
                                 options=var_options,
                                 multi=False, id="yvars",
                                 disabled=disabled_y)),
    ])
示例#5
0
def Exploration3D_Options(options):
    """
    Generate the layout of the dashboard.

    Args:
        options (list(dict)): Available datasets as options for `dcc.Dropdown`.

    Returns:
        A Dash element or list of elements.
    """

    return html.Div(
        children=[
            html.Div(
                [
                    # Choose a dataset
                    html.Div(create_dropdown("Available datasets",
                                             options,
                                             multi=False,
                                             id="dataset_choice_3d"),
                             className="vertical_dropdowns"),

                    # Available buttons and choices for plotting
                    html.Div(id="variable_choices_3d",
                             children=[
                                 html.Div(create_dropdown(f"{dim} variable",
                                                          options=[],
                                                          multi=False,
                                                          id=f"{dim}vars_3d"),
                                          className="vertical_dropdowns")
                                 for dim in ["x", "y", "z"]
                             ]),

                    # Export graph config
                    html.Div([
                        html.Br(),
                        html.Button("Export graph config 1",
                                    id="export_graph1"),
                        html.Button("Export graph config 2",
                                    id="export_graph2"),
                    ],
                             className="vertical_dropdowns"),
                ],
                className="col-sm-4"),

            # The graph itself
            html.Div([
                dcc.Graph(id="graph_3d"),
            ], className="col-sm-8"),
        ],
        className="row")
示例#6
0
def Exploration_Options(options):
    """
    Generate the layout of the dashboard.

    Args:
        options (list(dict)): Available datasets as options for `dcc.Dropdown`.

    Returns:
        A Dash element or list of elements.
    """

    return html.Div(children=[

        # Choose a dataset
        html.Div(create_dropdown(
            "Available datasets", options, multi=False,
            id="dataset_choice_2d"),
                 className="horizontal_dropdowns"),

        # Holds the name AND opens a modal for graph selection
        html.Button(
            "Choose a graph...", id="graph_choice_exploration", n_clicks=0),

        # modal with buttons for graphs
        html.Div([
            dbc.Modal([
                dbc.ModalHeader("Choose a graph type"),
                dbc.ModalBody(["2D graphs: ", html.Div(buttons)]),
                dbc.ModalFooter(
                    dbc.Button(
                        "Close", id="close_choose_graph", className="ml-auto"))
            ],
                      id="modal_choose_graph")
        ]),

        # Available buttons and choices for plotting
        html.Div(id="variable_choices_2d",
                 children=[
                     html.Div(create_dropdown(
                         "X variable", options=[], multi=False, id="xvars_2d"),
                              className="horizontal_dropdowns"),
                     html.Div(create_dropdown(
                         "Y variable", options=[], multi=False, id="yvars_2d"),
                              className="horizontal_dropdowns"),
                 ]),

        # The graph itself
        dcc.Graph(id="graph_2d"),
    ])
示例#7
0
def Clustering_Options(options):
    """
    Generate the layout of the dashboard.

    Args:
        options (list(dict)): Available datasets as options for `dcc.Dropdown`.

    Returns:
        A Dash element or list of elements.
    """

    return html.Div(children=[
        # Choose a dataset
        html.Div(create_dropdown("Available datasets",
                                 options,
                                 multi=False,
                                 id="dataset_choice_clustering"),
                 className="horizontal_dropdowns"),

        # Choose an algorithm
        html.Div(create_dropdown("Choose algorithm type",
                                 options=[
                                     {
                                         'label': 'DBSCAN',
                                         'value': 'dbscan'
                                     },
                                     {
                                         'label': 'K-Means Clustering',
                                         'value': 'kmc'
                                     },
                                 ],
                                 multi=False,
                                 id="algo_choice_clustering"),
                 className="horizontal_dropdowns"),

        ## Two empty divs to be filled by callbacks
        # Available choices for fitting
        html.Div(id="variable_choices_clustering"),

        #Available number of clusters
        html.P("Number of clusters:"),
        daq.NumericInput(id='clusters_input', min=0, value=3, max=10),
        # The results
        html.Div(id="training_results_clustering"),

        # The graph
        dcc.Graph(id="clustering_results"),
    ])
示例#8
0
def single_model_options(options):
    """
    Generate the layout of the dashboard.

    Args:
        options (list(dict)): Available datasets as options for `dcc.Dropdown`.

    Returns:
        A Dash element or list of elements.
    """

    return [

        # The main content
        html.Div(children=[

            # Choose type of metric to display
            dcc.Tabs(id="results_tabs", value='metrics', children=[
                dcc.Tab(label='Metrics', value='metrics'),
                dcc.Tab(label='Visualizations', value='visualizations'),
            ]),

            # Hidden divs for the intermediate results
            html.Div(id="hidden_results_metrics",
                     style={"display": "none"}),
            html.Div(id="hidden_results_visualizations",
                     style={"display": "none"}),

            # The fitting results (target of the tab menu)
            html.Div(id="fitting_report")
        ], id="training_results_div"),

        # The tab menu
        html.Div([
            # Choose a dataset
            html.Div(create_dropdown("Available datasets", options,
                                     multi=False, id="dataset_choice")),

            # Choose problem learning type
            html.Div(create_dropdown("Choose problem learning type", options=[
                {'label': 'Regression', 'value': 'regression'},
                {'label': 'Classification', 'value': 'classification'},
                {'label': 'Clustering', 'value': 'clustering'},
            ], multi=False, id="problem_type")),

            html.Div(id="variable_choices"),
        ], id="single_model_menu"),
    ]
示例#9
0
    def _render_variable_choices(dataset_choice,
                                 algo_choice,
                                 user_id,
                                 tab=tab):
        """
        Create a menu of dcc components for the user to choose fitting options. \
        This function is similar for all menus in the analyze tab, and only needs \
        the `app.callback` applied to it

        Args:
            dataset_choice (str): Name of dataset.
            algo_choice (str): The choice of algorithm type.
            user_id (str): Session/user id.
            tab (str): The tab you're currently on. Must be the same as the one \
                       the other callbacks are listening to.

        Returns:
            list: Dash elements.
        """

        df = get_data(dataset_choice, user_id)

        # Make sure all variables have a value before returning choices
        if any(x is None for x in [df, dataset_choice, algo_choice]):
            return [html.H4("Select dataset and algorithm first.")]

        # Truncate labels so they don't fill the whole dropdown
        options = [{'label': col[:35], 'value': col} for col in df.columns]

        layout = [
            html.Div(create_dropdown("X variable(s)",
                                     options,
                                     multi=True,
                                     id=f"xvars_{tab}"),
                     className="horizontal_dropdowns"),
            html.Div(create_dropdown("Y variable",
                                     options,
                                     multi=False,
                                     id=f"yvars_{tab}"),
                     className="horizontal_dropdowns"),
        ]

        return layout
示例#10
0
def Regression_Options(options):
    """
    Generate the layout of the dashboard.

    Args:
        options (list(dict)): Available datasets as options for `dcc.Dropdown`.

    Returns:
        A Dash element or list of elements.
    """

    return html.Div(children=[
        # Choose a dataset
        html.Div(create_dropdown("Available datasets",
                                 options,
                                 multi=False,
                                 id="dataset_choice_regression"),
                 className="horizontal_dropdowns"),

        # Choose an algorithm
        html.Div(create_dropdown("Choose algorithm type",
                                 options=[{
                                     'label': 'Linear Regression',
                                     'value': 'linr'
                                 }, {
                                     'label': 'SVM Regression',
                                     'value': 'svr'
                                 }, {
                                     'label': 'Decision Tree Regression',
                                     'value': 'dtr'
                                 }],
                                 multi=False,
                                 id="algo_choice_regression"),
                 className="horizontal_dropdowns"),

        ## Two empty divs to be filled by callbacks
        # Available choices for fitting
        html.Div(id="variable_choices_regression"),

        # The results
        html.Div(id="training_results_regression"),
    ])
示例#11
0
def KPI_Options(options):
    """
    Generate the layout of the dashboard.

    Args:
        options (list(dict)): Available datasets as options for `dcc.Dropdown`.

    Returns:
        A Dash element or list of elements.
    """

    return html.Div(children=[
        html.Div(create_dropdown("Available datasets",
                                 options,
                                 multi=False,
                                 id="dataset_choice_kpi"),
                 className="horizontal_dropdowns"),

        # TODO: use this for kpi/graph selection ?
        html.Div(create_dropdown("Choose graph type",
                                 options,
                                 multi=False,
                                 id="graph_choice_kpi",
                                 disabled=True),
                 className="horizontal_dropdowns"),
        html.Div(
            id="variable_choices_kpi",
            children=[
                html.Div(create_dropdown(
                    "X variables", options=[], multi=False, id="xvars_kpi"),
                         className="horizontal_dropdowns"),
                html.Div(create_dropdown(
                    "Y variable", options=[], multi=True, id="yvars_kpi"),
                         className="horizontal_dropdowns"),
                html.Div(create_dropdown("Bar Chart variable",
                                         options=[],
                                         multi=False,
                                         id="secondary_yvars_kpi"),
                         className="horizontal_dropdowns"),
            ]),
        dcc.Graph(id="graph_kpi"),
    ])
示例#12
0
文件: kpis.py 项目: jamaxey/EDA_miner
def KPI_Options(options):
    """
    Generate the layout of the dashboard.

    Args:
        options (list(dict)): Available datasets as options for `dcc.Dropdown`.

    Returns:
        A Dash element or list of elements.
    """

    return [

        # The main content
        html.Div(dcc.Graph(id="graph_kpi"), className="main-content-graph"),

        # The tab menu
        html.Div([
            # Choose a dataset
            html.Div(create_dropdown("Available datasets", options,
                                     multi=False, id="dataset_choice_kpi")),

            # TODO: use this for kpi/graph selection ?
            html.Div(create_dropdown("Choose graph type", options,
                                     multi=False, id="graph_choice_kpi",
                                     disabled=True)),

            # Available buttons and choices for plotting
            html.Div(id="variable_choices_kpi", children=[
                html.Div(create_dropdown("X variables", options=[],
                                         multi=False, id="xvars_kpi")),

                html.Div(create_dropdown("Y variable", options=[],
                                         multi=True, id="yvars_kpi")),

                html.Div(create_dropdown("Bar Chart variable", options=[],
                                         multi=False, id="secondary_yvars_kpi")),
            ])
        ], id="kpi_menu"),
    ]
示例#13
0
def Exploration_Options(options):
    """
    Generate the layout of the dashboard.

    Args:
        options (list(dict)): Available datasets as options for `dcc.Dropdown`.

    Returns:
        Two divs with Dash elements or lists of elements.
    """

    modals, divs = list(
        zip(*[make_trace_menu(x) for x in range(1, max_traces + 1)]))

    return [
        # The main content
        html.Div(dcc.Graph(id="graph"), className="main-content-graph"),

        # The tab menu
        html.Div([
            html.Div(
                [
                    html.Button("Add trace", id="add_trace", n_clicks=0),
                    html.Button("Remove trace", id="remove_trace", n_clicks=0),
                    html.Br(),
                    html.Br(),
                    dcc.Input(id="export_graph_name",
                              placeholder="Graph name..."),
                    html.Button(
                        "Export graph as...", id="export_graph", n_clicks=0),
                    html.Div(id="export_throwaway_div",
                             style={"display": "none"}),
                    html.Div(modals, id="modals"),

                    # Choose a dataset
                    html.Div(
                        create_dropdown("Available datasets",
                                        options,
                                        multi=False,
                                        id="dataset_choice")),

                    # The variable choices
                    html.Div([*divs], id="traces", className="traces-list"),
                    html.Div(id="traces_maker"),
                    # This is here to count the children
                    html.Div(0, id="hidden_div", style={"display": "none"}),
                ],
                id="chartmaker_menu")
        ])
    ]
示例#14
0
def make_trace_menu(n):
    """
    Helper function to create modals and trace menus.

    Args:
        n (int): The number/id of trace menu.

    Notes:
        Each trace needs a modal with buttons, a menu for choices, \
        and a callback to update the graph (probably with a "plot" button).
    """

    buttons = []
    for graph_type, (label, *_) in graph2d_configs.items():
        buttons.append(create_button(graph_type, label, n))

    # modal with buttons for graphs
    modal = html.Div([
        dbc.Modal([
            dbc.ModalHeader("Choose a graph type"),
            dbc.ModalBody(["2D graphs: ", html.Div(buttons)]),
            dbc.ModalFooter(
                dbc.Button("Close",
                           id=f"close_choose_graph_{n}",
                           className="ml-auto"))
        ],
                  id=f"modal_choose_graph_{n}")
    ])

    # Traces menus
    div = html.Div(
        [

            # Menu header
            html.Div([
                html.P(f"trace {n}", className="trace-title-text"),
            ],
                     className="trace-title"),

            # Available buttons and choices for plotting
            # Holds the name AND opens a modal for graph selection
            html.Div([
                html.Div("Type", className="trace-variable-name"),
                html.Button("Scatterplot",
                            value="scatterplot",
                            id=f"graph_choice_{n}",
                            n_clicks=0,
                            className="plot-menu-input-button"),
            ],
                     className="trace-menu-row"),

            # Available variable choices
            html.Div(create_dropdown(
                "X", options=[], type_="trace", multi=False, id=f"xvars_{n}"),
                     className="plot-menu-input-div"),
            html.Div(create_dropdown(
                "Y", options=[], type_="trace", multi=False, id=f"yvars_{n}"),
                     className="plot-menu-input-div"),

            # Z-vars are not always needed, so keep them disabled and hidden
            html.Div(create_dropdown("Z",
                                     options=[],
                                     disabled=True,
                                     type_="trace",
                                     multi=False,
                                     id=f"zvars_{n}"),
                     className="plot-menu-input-div",
                     style={"display": "none"},
                     id=f"z_vars_div_{n}"),
        ],
        style={"display": "none"},
        id=f"trace_{n}",
        className="trace-container")

    return modal, div
示例#15
0
def render_variable_choices_pipeline(pipeline_choice):
    """
    Create a menu of dcc components to select pipeline and variables.

    Args:
        algo_choice_pipeline (str): Choice among (pre)defined pipelines.

    Returns:
        list: Dash elements.
    """

    user_id = current_user.username

    # Make sure all variables have a value before returning choices
    if pipeline_choice is None:
        return [html.H4("Select a pipeline first.")]

    pipeline = dill.loads(redis_conn.get(pipeline_choice))

    # Reminder: pipelines are named after their graphs following
    # these conventions:
    # Pipeline: userid_pipeline_userProvidedName_lastNodeID
    # Graph: userid_graph_userProvidedName

    # Get the graph for the model
    name = pipeline_choice.split("_")[2]
    model = dill.loads(redis_conn.get(f"{user_id}_graph_{name}"))

    # For each input node
    columns = []
    for input_node in model.input_nodes:
        dataset = input_node.params["dataset"]

        # Append the input_node.id to the keys in case of columns
        # with the same name.
        cols = list(
            f"{key}_{input_node.id}"
            for key in get_data_schema(dataset, redis_conn)["types"].keys())
        columns.extend(cols)

    var_options = [{"label": col, "value": col} for col in columns]

    # e.g.: linr_001
    output_node_id = "_".join(pipeline_choice.split("_")[-2:])
    output_node = model.graph.node_collection[output_node_id]

    # Depending on the problem type, dis/allow for a Y variable
    if any(
            isinstance(output_node.model_class(), base)
            for base in [ClassifierMixin, RegressorMixin]):

        # Supervised
        disabled_y = False

    else:
        # Unsupervised
        disabled_y = True

    return html.Div([
        html.Div(
            create_dropdown("Choose variable(s) X",
                            options=var_options,
                            multi=True,
                            id="xvars_pipeline")),
        html.Div(
            create_dropdown("Choose target variable Y",
                            options=var_options,
                            multi=False,
                            id="yvars_pipeline",
                            disabled=disabled_y)),
        html.Div([
            html.H6("Export trained model..."),
            html.Button("Export!", id="export_model_button"),
        ])
    ])
示例#16
0
def Network_Options(options):
    """
    Generate the layout of the dashboard.

    Args:
        options (list(dict)): Available datasets as options for `dcc.Dropdown`.

    Returns:
        A Dash element or list of elements.
    """

    return html.Div(
        children=[
            html.Div(
                [
                    # Choose a dataset
                    html.Div(create_dropdown("Available datasets",
                                             options,
                                             multi=False,
                                             id="dataset_choice_network"),
                             className="vertical_dropdowns"),

                    # Available buttons and choices for plotting
                    html.Div(create_dropdown(
                        "In-node", options=[], multi=False, id="in_node"),
                             className="vertical_dropdowns"),
                    html.Div(create_dropdown(
                        "Out-node", options=[], multi=False, id="out_node"),
                             className="vertical_dropdowns"),
                    html.Div(create_dropdown(
                        "Layout",
                        id='dropdown-callbacks-1',
                        value='grid',
                        multi=False,
                        clearable=False,
                        options=[
                            {
                                'label': name,
                                'value': name
                            } for name in
                            ['grid', 'random', 'circle', 'concentric', 'cose']
                        ]),
                             className="vertical_dropdowns")
                ],
                className="col-sm-3"),

            # The graph itself
            html.Div([
                cyto.Cytoscape(id='cytoscape_network_graph',
                               layout={'name': 'preset'},
                               style={
                                   'width': '100%',
                                   'height': '700px'
                               },
                               elements=[{
                                   'data': {
                                       'id': 'one',
                                       'label': 'Example Node 1'
                                   },
                                   'position': {
                                       'x': 75,
                                       'y': 75
                                   }
                               }, {
                                   'data': {
                                       'id': 'two',
                                       'label': 'Example Node 2'
                                   },
                                   'position': {
                                       'x': 200,
                                       'y': 200
                                   }
                               }, {
                                   'data': {
                                       'source': 'one',
                                       'target': 'two'
                                   }
                               }]),
            ],
                     className="col-sm-9"),
        ],
        className="row")
示例#17
0
def Map_Options(options):
    """
    Generate the layout of the dashboard.

    Args:
        options (list(dict)): Available datasets as options for `dcc.Dropdown`.

    Returns:
        A Dash element or list of elements.
    """

    return html.Div(children=[

        html.Div([
            # Choose a dataset
            html.Div(create_dropdown("Available datasets", options,
                                     multi=False, id="dataset_choice_maps"),
                     className="vertical_dropdowns"),
            # Choose a map type
            html.Div(create_dropdown("Map type", [
                {"label": "Choropleth", "value": "agg_choropleth"},
                {"label": "Simple geoscatter", "value": "geoscatter"},
                {"label": "Lines on map", "value": "maplines"},
            ], multi=False, id="map_type_choice"),
                     className="vertical_dropdowns"),

            # Available buttons and choices for plotting
            html.Div(create_dropdown("Colorscale", options=[
                {"label": v, "value": v}
                for v in colorscale_list
            ], multi=False, id="colorscale", value="Jet"),
                     className="vertical_dropdowns"),
            html.Div(create_dropdown("Latitude", options=[],
                                     multi=False, id="lat_var"),
                     className="vertical_dropdowns"),
            html.Div(create_dropdown("Longitude", options=[],
                                     multi=False,
                                     id="lon_var"),
                     className="vertical_dropdowns"),
            html.Div(create_dropdown("Country", options=[],
                                     multi=False,
                                     id="country"),
                     className="vertical_dropdowns"),
            html.Div(create_dropdown("Z variable", options=[],
                                     multi=False, id="z_var"),
                     className="vertical_dropdowns"),
            html.Div(create_dropdown("Choose aggregation type", options=[
                {"label": "Sum", "value": "sum"},
                {"label": "Average", "value": "mean"},
                {"label": "Count", "value": "count"},
                {"label": "Max", "value": "max"},
                {"label": "Min", "value": "min"},
            ], multi=False, id="aggregator_field", value="count"),
                     className="vertical_dropdowns"),
            html.Div(create_dropdown("Destination latitude", options=[],
                                     multi=False, id="dest_lat"),
                     className="vertical_dropdowns"),
            html.Div(create_dropdown("Destination longitude", options=[],
                                     multi=False, id="dest_long"),
                     className="vertical_dropdowns"),
            html.Div(create_dropdown("Map projection style", options=[
                {"label": "Equirectangular", "value": "equirectangular"},
                {"label": "Azimuthal equal area", "value": "azimuthal equal area"},
                {"label": "Orthographic", "value": "orthographic"},

            ],
                                     multi=False, id="projection_type"),
                     className="vertical_dropdowns"),

        ], className="col-sm-3"),

        # The graph itself
        html.Div([
            dcc.Graph(id="map_graph", style={"minHeight": "650px"})
        ], className="col-sm-9"),
    ], className="row")
示例#18
0
def Pipeline_Options(options):
    """
    Generate the layout of the dashboard.

    Args:
        options (list(dict)): Available datasets as options for `dcc.Dropdown`.

    Returns:
        A Dash element or list of elements.
    """

    user_id = current_user.username

    available_pipelines = {
        k.decode(): redis_conn.get(k)
        for k in redis_conn.keys(f'{user_id}_pipeline_*')
    }

    return [

        # The right side with the results
        html.Div(
            [

                # Choose type of metric to display
                dcc.Tabs(id="results_tabs_pipeline",
                         value='metrics',
                         children=[
                             dcc.Tab(label='Metrics', value='metrics'),
                             dcc.Tab(label='Visualizations',
                                     value='visualizations'),
                         ]),

                # Hidden divs for the intermediate results
                html.Div(id="hidden_results_metrics_pipeline",
                         style={"display": "none"}),
                html.Div(id="hidden_results_visualizations_pipeline",
                         style={"display": "none"}),

                # A modal for exporting the model
                dbc.Modal([
                    dbc.ModalHeader("Trained model export report."),
                    dbc.ModalBody(id="modal_body")
                ],
                          id=f"export_model_modal",
                          is_open=False),

                # The fitting results (target of the tab menu)
                html.Div(id="fitting_report_pipeline")
            ],
            id="training_results_div"),

        # The tab menu
        html.Div(
            [

                # Choose a dataset
                html.Div(
                    create_dropdown("Available pipelines",
                                    options=[{
                                        'label': f'Pipeline --> {pipe_name}',
                                        'value': pipe_name
                                    } for pipe_name in available_pipelines],
                                    multi=False,
                                    id="pipeline_choice")),
                html.Div(id="variable_choices_pipeline"),
            ],
            id="pipelines_menu"),
    ]
示例#19
0
                dbc.ModalBody(
                    children=[

                        # Stuff inside the modal
                        html.Div(
                            id='sidebar_collapsible_button_modify_node',
                            children=[
                                html.Div(
                                    id="inspector",
                                    children=[
                                        html.Div(
                                            [
                                                *create_dropdown(
                                                    "Options", [{
                                                        "label":
                                                        "No node selected",
                                                        "value": "none"
                                                    }],
                                                    id="modify_option_dropdown"
                                                ),
                                                dcc.RadioItems(
                                                    options=[{
                                                        "label":
                                                        "No node selected",
                                                        "value": "none"
                                                    }],
                                                    id="modify_node_params",
                                                    labelStyle={
                                                        'display':
                                                        'inline-block',
                                                        'margin': '5px'
                                                    })
示例#20
0
文件: maps.py 项目: jamaxey/EDA_miner
def Map_Options(options):
    """
    Generate the layout of the dashboard.

    Args:
        options (list(dict)): Available datasets as options for `dcc.Dropdown`.

    Returns:
        A Dash element or list of elements.
    """

    return [

        # The main content
        html.Div(dcc.Graph(id="map_graph"), className="main-content-graph"),

        html.Div([
            # Choose a dataset
            html.Div(create_dropdown("Available datasets", options,
                                     multi=False, id="dataset_choice_maps")),

            # The tab menu
            html.Div(create_dropdown("Map type", [
                {"label": "Choropleth", "value": "agg_choropleth"},
                {"label": "Simple geoscatter", "value": "geoscatter"},
                {"label": "Lines on map", "value": "maplines"},
            ], multi=False, id="map_type_choice")),

            # Available buttons and choices for plotting
            html.Div(create_dropdown("Colorscale", options=[
                {"label": v, "value": v}
                for v in colorscale_list
            ], multi=False, id="colorscale", value="Jet")),

            html.Div(create_dropdown("Latitude", options=[],
                                     multi=False, id="lat_var")),

            html.Div(create_dropdown("Longitude", options=[],
                                     multi=False,
                                     id="lon_var")),

            html.Div(create_dropdown("Country", options=[],
                                     multi=False,
                                     id="country")),

            html.Div(create_dropdown("Z variable", options=[],
                                     multi=False, id="z_var")),

            # Relevant for `agg_choropleth`
            html.Div(create_dropdown("Choose aggregation type", options=[
                {"label": "Sum", "value": "sum"},
                {"label": "Average", "value": "mean"},
                {"label": "Count", "value": "count"},
                {"label": "Max", "value": "max"},
                {"label": "Min", "value": "min"},
            ], multi=False, id="aggregator_field", value="count")),

            # Relevant for `maplines`
            html.Div(create_dropdown("Destination latitude", options=[],
                                     multi=False, id="dest_lat")),
            html.Div(create_dropdown("Destination longitude", options=[],
                                     multi=False, id="dest_long")),

            # How to draw the map and represent distances
            html.Div(create_dropdown("Map projection style", options=[
                {"label": "Equirectangular", "value": "equirectangular"},
                {"label": "Azimuthal equal area", "value": "azimuthal equal area"},
                {"label": "Orthographic", "value": "orthographic"},
            ], multi=False, id="projection_type")),

        ], id="map_menu"),
    ]
示例#21
0
def render_variable_choices_pipeline(algo_choice_pipeline, user_id):
    """
    Create a menu of dcc components to select pipeline and variables.

    Args:
        algo_choice_pipeline (str): Choice among (pre)defined pipelines.
        user_id (str): Session/user id.

    Returns:
        list: Dash elements.
    """

    # Make sure all variables have a value before returning choices
    if algo_choice_pipeline is None:
        return [html.H4("Select a pipeline first.")]

    model = dill.loads(r.get(algo_choice_pipeline))

    input_node = pipeline_creator.find_pipeline_node(
        pipeline_classes.BaseInput)(model)

    terminal_node = pipeline_creator.find_pipeline_node(
        pipeline_classes.TerminalNode)(model)

    # defaults
    layout = []
    options = []

    if isinstance(input_node, pipeline_classes.GenericInput):
        try:
            dataset_choice = input_node.dataset
        except AttributeError:
            return [html.H4("Something went wrong with the input")]

        if isinstance(input_node, pipeline_classes.TwitterAPI):
            layout += [
                html.Button("Fit model", id="fit_model", n_clicks=0),

                # Debugger
                html.Div(
                    dcc.Dropdown(options=[],
                                 multi=True,
                                 id="xvars_pipeline",
                                 style={"display": "none"})),
            ]

        else:
            df = get_data(dataset_choice, user_id)

            # Truncate labels so they don't fill the whole dropdown
            options = [{'label': col[:35], 'value': col} for col in df.columns]

            layout += [
                html.Div(create_dropdown("X variable(s)",
                                         options,
                                         multi=True,
                                         id="xvars_pipeline"),
                         className="horizontal_dropdowns"),

                # to debug the next callback
                html.Button("Fit model",
                            id="fit_model",
                            n_clicks=0,
                            style={"display": "none"})
            ]

    else:
        layout += [
            # Debuggers
            html.Button("Fit model",
                        id="fit_model",
                        n_clicks=0,
                        style={"display": "none"}),
            html.Div(
                dcc.Dropdown(options=[],
                             multi=True,
                             id="xvars_pipeline",
                             style={"display": "none"})),
        ]

    if not isinstance(terminal_node, pipeline_classes.UnsupervisedLearner):
        layout += [
            html.Div(dcc.Dropdown(options=options,
                                  multi=False,
                                  id="yvars_pipeline"),
                     className="horizontal_dropdowns")
        ]

    else:
        # Only existing for debugging the next callback, no yvars needed
        layout += [
            dcc.Dropdown(options=[],
                         id="yvars_pipeline",
                         style={"display": "none"})
        ]

    return layout