Python dash.dependencies.State() Examples

The following are 4 code examples of dash.dependencies.State(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module dash.dependencies , or try the search function .
Example #1
Source File: main.py    From deep_architect with MIT License 5 votes vote down vote up
def get_state(self, attribute_name):
        return State(self.full_name, attribute_name) 
Example #2
Source File: _parameter_distribution.py    From webviz-subsurface with GNU General Public License v3.0 4 votes vote down vote up
def set_callbacks(self, app):
        @app.callback(
            Output(self.ids("parameter"), "value"),
            [
                Input(self.ids("prev-btn"), "n_clicks"),
                Input(self.ids("next-btn"), "n_clicks"),
            ],
            [State(self.ids("parameter"), "value")],
        )
        def _set_parameter_from_btn(_prev_click, _next_click, column):

            ctx = dash.callback_context.triggered
            if ctx is None:
                raise PreventUpdate
            callback = ctx[0]["prop_id"]
            if callback == f"{self.ids('prev-btn')}.n_clicks":
                column = prev_value(column, self.parameter_columns)
            elif callback == f"{self.ids('next-btn')}.n_clicks":
                column = next_value(column, self.parameter_columns)
            else:
                column = self.parameter_columns[0]
            return column

        @app.callback(
            Output(self.ids("graph"), "data"), [Input(self.ids("parameter"), "value")]
        )
        def _set_parameter(column):
            param = self.parameters[[column, "REAL", "ENSEMBLE"]]

            ensembles = param["ENSEMBLE"].unique().tolist()

            iterations = []
            values = []
            labels = []

            for ensemble in ensembles:
                df = param[param["ENSEMBLE"] == ensemble]
                iterations.append(ensemble)
                values.append(df[column].tolist())
                labels.append([f"Realization {real}" for real in df["REAL"].tolist()])

            return {"iterations": iterations, "values": values, "labels": labels} 
Example #3
Source File: custom_geojson.py    From dtale with GNU Lesser General Public License v2.1 4 votes vote down vote up
def init_callbacks(dash_app):
    @dash_app.callback(
        [
            Output("output-geojson-upload", "children"),
            Output("geojson-dropdown", "options"),
        ],
        [Input("upload-geojson", "contents")],
        [State("upload-geojson", "filename")],
    )
    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

    @dash_app.callback(
        [
            Output("featureidkey-dropdown", "options"),
            Output("featureidkey-dropdown", "disabled"),
            Output("featureidkey-dropdown", "placeholder"),
        ],
        [Input("geojson-dropdown", "value")],
    )
    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

    @dash_app.callback(
        Output("geojson-modal", "is_open"),
        [
            Input("open-geojson-modal", "n_clicks"),
            Input("close-geojson-modal", "n_clicks"),
        ],
        [State("geojson-modal", "is_open")],
    )
    def toggle_modal(n1, n2, is_open):
        if n1 or n2:
            return not is_open
        return is_open 
Example #4
Source File: common_features.py    From dash-bio with MIT License 4 votes vote down vote up
def simple_app_callback(
        app,
        dash_duo,
        component_id,
        test_prop_name,
        test_prop_value,
        prop_value_type,
        validation_fn=None,
        take_snapshot=False
):
    if validation_fn is None:
        def validation_fn(x): return x == test_prop_value

    @app.callback(
        Output(component_id, test_prop_name),
        [Input('submit-prop-button', 'n_clicks')],
        [State('prop-value', 'value')]
    )
    def setup_click_callback(nclicks, value):
        if nclicks is not None and nclicks > 0:
            return process_value(value, prop_value_type)
        raise dash.exceptions.PreventUpdate()

    @app.callback(
        Output('pass-fail-div', 'children'),
        [Input(component_id, test_prop_name)],
        [State('submit-prop-button', 'n_clicks')]
    )
    def simple_callback(prop_value, nclicks):
        if nclicks is None or nclicks == 0:
            return None
        passfail = PASS if validation_fn(prop_value) else FAIL
        return html.Div(passfail, id='passfail')

    _start_app_server(
        app,
        dash_duo,
        component_id,
        test_prop_name,
        test_prop_value,
        take_snapshot
    )