Example #1
0
 def update_geojson(contents, filename):
     if filename is None:
         raise PreventUpdate
     geojson_options = [build_option(ct["key"]) for ct in get_custom_geojson()]
     try:
         geojson_key = load_geojson(contents, filename)
         geojson_options.append(build_option(geojson_key))
         return "{} uploaded!".format(geojson_key), geojson_options
     except BaseException as ex:
         return str(ex), geojson_options
Example #2
0
 def populate_col_dropdowns(is_open, input_data):
     if not is_open:
         raise PreventUpdate
     y = make_list(input_data.get("y"))
     z = make_list(input_data.get("z"))
     col_options = [
         build_option(sub_col) for sub_col in (y if not len(z) else z)
     ]
     return [col_options for _ in range(10)]
Example #3
0
 def update_featureidkey_options(geojson):
     geojson_data = get_custom_geojson(geojson)
     placeholder = "Select uploaded data"
     if geojson_data is None or isinstance(geojson_data, list):
         return [], False, placeholder
     disabled = geojson_data["type"] != "FeatureCollection"
     placeholder = "id" if disabled else placeholder
     if geojson_data and not disabled:
         return (
             [build_option(p) for p in geojson_data.get("properties", [])],
             disabled,
             placeholder,
         )
     return [], disabled, placeholder
Example #4
0
 def build_x_dropdown(is_open, pathname, inputs, chart_inputs, yaxis_data, map_data):
     if not is_open:
         raise PreventUpdate
     df = global_state.get_data(get_data_id(pathname))
     all_inputs = combine_inputs(
         dash_app, inputs, chart_inputs, yaxis_data, map_data
     )
     chart_type, x, y, z, group, map_val, animate_by = (
         all_inputs.get(p)
         for p in ["chart_type", "x", "y", "z", "group", "map_val", "animate_by"]
     )
     if chart_type == "maps":
         if all_inputs.get("map_type") == "choropleth":
             x = all_inputs["loc"]
         else:
             x = "lat_lon"
         x_options = build_selections(map_val, animate_by)
     else:
         x_options = build_selections(z or y, animate_by)
     col_opts = list(build_cols(df.columns, get_dtypes(df)))
     x_options = [build_option(c, l) for c, l in col_opts if c not in x_options]
     return x_options, x
Example #5
0
def build_geojson_upload(loc_mode, geojson_key=None, featureidkey=None):
    curr_geojson = get_custom_geojson(geojson_key)

    featureidkey_options = []
    featureidkey_value = featureidkey
    featureidkey_placeholder = "Select uploaded data"
    disabled = False
    if curr_geojson and not isinstance(curr_geojson, list):
        if curr_geojson.get("type") == "FeatureCollection":
            featureidkey_options = [
                build_option(fik) for fik in curr_geojson["properties"]
            ]
        else:
            featureidkey_value = None
            disabled = True
            featureidkey_placeholder = "id"

    return [
        html.Div(
            [
                html.Div(
                    [
                        dcc.Upload(
                            html.Div(
                                html.Span(
                                    html.Span(
                                        "Upload File",
                                        style=dict(whiteSpace="pre-line")),
                                    className=
                                    "input-group-addon d-block pt-1 pb-0 pointer",
                                ),
                                className="input-group mr-3",
                                id="upload-geojson-btn",
                            ),
                            id="upload-geojson",
                        ),
                    ],
                    className="col-auto",
                ),
                html.Div(id="output-geojson-upload",
                         className="col mt-auto mb-auto"),
            ],
            className="row pb-5",
        ),
        html.Div(
            [
                build_input(
                    "geojson",
                    dcc.Dropdown(
                        id="geojson-dropdown",
                        options=[
                            build_option(ct["key"]) for ct in CUSTOM_GEOJSON
                        ],
                        placeholder="Select uploaded data",
                        style=dict(width="inherit"),
                        value=geojson_key
                        if loc_mode == "geojson-id" else None,
                    ),
                    className="col-md-6",
                    id="geojson-input",
                ),
                build_input(
                    "featureidkey",
                    dcc.Dropdown(
                        id="featureidkey-dropdown",
                        options=featureidkey_options,
                        placeholder=featureidkey_placeholder,
                        style=dict(width="inherit"),
                        disabled=disabled,
                        value=featureidkey_value,
                    ),
                    className="col-md-6",
                    id="featureidkey-input",
                ),
            ],
            className="row",
        ),
    ]
Example #6
0
def build_body(ext_aggs):
    col_inputs = [html.Div(id="extended-agg-errors")]
    for i in INPUT_IDS:
        ext_agg = ext_aggs[i - 1] if len(ext_aggs) >= i else {}
        col_inputs.append(
            html.Div(
                [
                    html.Span(
                        "{}.".format(i),
                        className="col-auto pr-0 mt-auto mb-auto ext-agg-id",
                    ),
                    build_input(
                        text("Col"),
                        dcc.Dropdown(
                            id="col-dropdown-{}".format(i),
                            placeholder=text("Select"),
                            style=dict(width="inherit"),
                            value=ext_agg.get("col"),
                        ),
                        className="col-md-3",
                    ),
                    build_input(
                        text("Agg"),
                        dcc.Dropdown(
                            id="agg-dropdown-{}".format(i),
                            options=[
                                build_option(v, text(AGGS[v])) for v in [
                                    "count",
                                    "nunique",
                                    "sum",
                                    "mean",
                                    "rolling",
                                    "corr",
                                    "first",
                                    "last",
                                    # "drop_duplicates",
                                    "median",
                                    "min",
                                    "max",
                                    "std",
                                    "var",
                                    "mad",
                                    "prod",
                                    "pctsum",
                                    "pctct",
                                ]
                            ],
                            placeholder=text("Select"),
                            style=dict(width="inherit"),
                            value=ext_agg.get("agg"),
                        ),
                        className="col-md-3",
                    ),
                    html.Div(
                        [
                            build_input(
                                text("Window"),
                                dcc.Input(
                                    id="window-input-{}".format(i),
                                    type="number",
                                    placeholder=text("Enter Days"),
                                    className="form-control text-center",
                                    style={"lineHeight": "inherit"},
                                    value=ext_agg.get("window"),
                                ),
                                className="col-md-6",
                            ),
                            build_input(
                                text("Computation"),
                                dcc.Dropdown(
                                    id="rolling-comp-dropdown-{}".format(i),
                                    options=[
                                        build_option("corr",
                                                     text("Correlation")),
                                        build_option("count", text("Count")),
                                        build_option("cov",
                                                     text("Covariance")),
                                        build_option("kurt", text("Kurtosis")),
                                        build_option("max", text("Maximum")),
                                        build_option("mean", text("Mean")),
                                        build_option("median", text("Median")),
                                        build_option("min", text("Minimum")),
                                        build_option("skew", text("Skew")),
                                        build_option(
                                            "std",
                                            text("Standard Deviation"),
                                        ),
                                        build_option("sum", text("Sum")),
                                        build_option("var", text("Variance")),
                                    ],
                                    placeholder=text("Select"),
                                    style=dict(width="inherit"),
                                    value=ext_agg.get("rolling_comp"),
                                ),
                                className="col-md-6 pl-0",
                            ),
                        ],
                        id="rolling-inputs-{}".format(i),
                        style=show_style(ext_agg.get("agg") == "rolling",
                                         display_style="inherit"),
                        className="col-md-6 row p-0",
                    ),
                ],
                className="row pb-3",
            ))
    return html.Div(col_inputs, id="extended-agg-body")