本文整理匯總了Python中dash.dependencies.State方法的典型用法代碼示例。如果您正苦於以下問題:Python dependencies.State方法的具體用法?Python dependencies.State怎麽用?Python dependencies.State使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dash.dependencies
的用法示例。
在下文中一共展示了dependencies.State方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_state
# 需要導入模塊: from dash import dependencies [as 別名]
# 或者: from dash.dependencies import State [as 別名]
def get_state(self, attribute_name):
return State(self.full_name, attribute_name)
示例2: set_callbacks
# 需要導入模塊: from dash import dependencies [as 別名]
# 或者: from dash.dependencies import State [as 別名]
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}
示例3: init_callbacks
# 需要導入模塊: from dash import dependencies [as 別名]
# 或者: from dash.dependencies import State [as 別名]
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
示例4: simple_app_callback
# 需要導入模塊: from dash import dependencies [as 別名]
# 或者: from dash.dependencies import State [as 別名]
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
)