仪表板中的有条件输入

发布于 2025-01-22 19:29:34 字数 891 浏览 3 评论 0原文

是否可以在仪表板上进行有条件的输入?以下是我的代码。 的是,我希望仅在main_tab =='a''和main_tab =='b'时才成为输入

@app.callback(
    Output('store-data', 'data'),
    Input("inputid", "n_submit"),
    Input("search-button","n_clicks"),
    Input("tabs-main","value"),
    Input("tabs","value"),
    State("inputid", "value"),
    prevent_initial_callback=True,
)
def store_data(n_submit,n_clicks,main_tab,tab,id_value):
    if n_submit or n_clicks>0:
        if main_tab=='A':
            uniqueid = b64.encode(id_value)
            locations_staging = query_staging.get_location(uniqueid,tab)
            data = query_staging.get_data(locations_staging)
            return data
        elif main_tab=="B":
            uniqueid = b64.encode(id_value)
            locations_cu = query_cu.get_location(uniqueid)
            data = query_cu.get_data(locations_cu)
            return data

我想完成 ?

Is it possible to make Input conditional in dash? Below is my code. What I want to accomplish is, I want the tabs to be the input only if the main_tab == 'A', and if the main_tab=='B', I want the tab to be state (not input)

@app.callback(
    Output('store-data', 'data'),
    Input("inputid", "n_submit"),
    Input("search-button","n_clicks"),
    Input("tabs-main","value"),
    Input("tabs","value"),
    State("inputid", "value"),
    prevent_initial_callback=True,
)
def store_data(n_submit,n_clicks,main_tab,tab,id_value):
    if n_submit or n_clicks>0:
        if main_tab=='A':
            uniqueid = b64.encode(id_value)
            locations_staging = query_staging.get_location(uniqueid,tab)
            data = query_staging.get_data(locations_staging)
            return data
        elif main_tab=="B":
            uniqueid = b64.encode(id_value)
            locations_cu = query_cu.get_location(uniqueid)
            data = query_cu.get_data(locations_cu)
            return data

How to accomplish this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荆棘i 2025-01-29 19:29:34

您可以在回调中创建条件。但是问题可能是当您想读取状态和输入的值以制定条件时,因为它们是模块上的类dash.depentencies。因此,您无法制定类似的条件:

 State('input-1-state', 'value') if Input('submit-button-state', 'n_clicks') > 1
                                 else State('input-2-state', 'value')

您可以使用帮助(输入)来阅读有关输入和状态的更多信息。

我认为您可以遵循当前的方法来制定调理。

You can create a condition inside a callback. But the problem might be when you want to read the values of State and Input to make a condition because they are classes on module dash.dependencies. Therefore, you cannot make a condition like:

 State('input-1-state', 'value') if Input('submit-button-state', 'n_clicks') > 1
                                 else State('input-2-state', 'value')

You can use help(Input) to read more about Input and State.

I think you can follow your current way to make conditioning.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文