def update_hist(selection, zoom_range, n_click, url, selected_col):

    #blank before selection
    if (selection is None) or (selection == []):
        return blank_fig()

    #get triggered dictionary
    trigger_list = dash.callback_context.triggered[0]["prop_id"]

    #is button been triggered?
    reset_df = True if 'reset-button.n_clicks' in trigger_list else False

    df = import_dataset()

    #list of key to check if 'auto' is in any key
    is_auto_zoom = any(['auto' in x for x in zoom_range.keys()])

    if (not is_auto_zoom) and (not reset_df):
        name_range_list = ['x', 'y']
        for i, col in enumerate(selected_col):
            axis_string = f'{name_range_list[i]}axis'
            df = df[(df[col] >= zoom_range[f'{axis_string}.range[0]'])
                    & (df[col] <= zoom_range[f'{axis_string}.range[1]'])]
    df[selection] = df[selection].astype(str)

    fig = get_histogram(df, selection)

    return fig
def update_scatter(selection, clicked, n_click, url):

    #blank before selection
    if (selection is None) or (selection == []):
        return blank_fig()

    #get triggered dictionary
    trigger_list = dash.callback_context.triggered[0]["prop_id"]

    #is button been triggered?
    reset_df = True if 'reset-button.n_clicks' in trigger_list else False

    df = import_dataset()

    #filter data index based on clicked hist
    if (clicked is not None) and (not reset_df):
        clicked_index = clicked['points'][0]['pointNumbers']
        df = df[df.index.isin(clicked_index)]

    #assign x
    x_selection = selection[0]

    #return histogram
    if (len(selection) == 1):

        fig = get_histogram(df, x_selection)
    else:
        y_selection = selection[1]

        fig = get_scatter(df, x_selection, y_selection)

    return fig
Beispiel #3
0
def update_dataset(url):

    df = import_dataset()

    #need to import something
    if df is None:
        return [None, None]

    columns = [{"name": i, "id": i} for i in df.columns]

    return [columns, df.to_dict('records')]
Beispiel #4
0
def update_info_rows(rows, url):

    df = import_dataset()

    #need to import something
    if df is None:
        return [None]

    dff = df if rows is None else pd.DataFrame(rows)
    num_rows, num_cols = dff.shape

    return [html.P(f'The dataset has {num_rows} rows and {num_cols} columns.')]
Beispiel #5
0
def update_table(rows, url):

    _, metadata_type = import_metadata(get_type_colname=True)

    df = import_dataset()

    #need to import something
    if (df is None) or (metadata_type is None):
        return blank_fig()

    dff = df if rows is None else pd.DataFrame(rows)

    numeric_col = [x for x in metadata_type['numeric'] if x in dff.columns]

    numeric_info = [[
        col,
        np.round(dff[col].mean(), 2),
        np.round(dff[col].std(), 2),
        np.round(dff[col].median(), 2),
        np.round(dff[col].min(), 2),
        np.round(dff[col].max(), 2),
    ] for col in numeric_col]

    #reshape
    numeric_info = np.array(numeric_info).T.tolist()

    fig_table = go.Figure(data=[
        go.Table(header=dict(
            values=['Columns', 'Mean', 'Std', 'Median', 'Min', 'Max'],
            align=['left', 'center']),
                 cells=dict(values=numeric_info, align=['left', 'center']))
    ],
                          layout=go.Layout(template='plotly_white',
                                           margin={'l': 0}))

    return fig_table
Beispiel #6
0
def update_graphs(string_col, rows, url):

    if string_col is None:
        return blank_fig()

    df = import_dataset()

    dff = df if rows is None else pd.DataFrame(rows)

    # if you filter and have empty dataframe
    if (string_col not in dff.columns):
        return blank_fig()

    #coherce to string... integer will be displayed as str
    dff_string_unique = [str(x) for x in dff[string_col].unique().tolist()]
    dff_string_count = [(dff[string_col] == cat).sum()
                        for cat in dff[string_col].unique()]

    fig = go.Figure(data=go.Bar(x=dff_string_unique, y=dff_string_count),
                    layout=go.Layout(template='plotly_white',
                                     title=string_col,
                                     margin={'l': 0}))

    return fig