Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the callback of Python Visual Dash tool

Shulou Source: shulou.com Published: 2022-06-02 03:26:13 09月27日 Update

Today, I will talk to you about the use of Python visualization Dash tool callback, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

The "callback" in Dash is in the form of a decorator, combined with a self-designed callback function to realize the asynchronous communication between the front and back ends.

Callbacks can achieve single input, single output; single input, multiple outputs; multiple inputs, multiple outputs; single / multiple inputs, single / multiple outputs, as long as the parameter names are different.

Callback is more convenient for asynchronous interaction between front and back ends.

Province2city_dict = {

'Sichuan Province': 'Chengdu'

'Shaanxi Province':'Xi'an City'

'Guangdong Province': 'Guangzhou'

}

Flowertype_dict = {

'setosa':'1'

'versicolor':'2'

'virginnica':'3'

}

App.layout=html.Div ([html.Div ('Div logo', id='logo'))

Html.Div ('Div header', id='header')

Html.Div ([

Html.Div ([

Html.Div ('Div left-top', id='left-top')

Html.Div ('Div left-middle', id='left-middle')

Html.Div ('Div left-bottom', id='left-bottom')

], id='mleft')

Html.Div ([

Html.H1 ('query provincial capital cities according to provincial name:')

Html.Br ()

Dcc.Dropdown (id='province'

Options= [{'label':' Sichuan', 'value':' Sichuan'}

{'label':' Shaanxi', 'value':' Shaanxi'}

{'label':' Guangdong', 'value':' Guangdong'}]

Value=' Sichuan')

Html.P (id='city')

Html.Div ([

Html.Label ('Gender')

Html.Div ([

Dcc.Dropdown (# functional component, set the id value as the tag in the callback function associated with the tag

Id='gender'

Options= [{'label': I,' value': I} for i in ['woman', 'man']

Value=' woman')

])

Html.P ('Test multiple inputs and single output:', id='multinputsimpleoutput')

Html.P ('Test multiple inputs and single output, the same input variable outputs different variables:', id='multinputsimpleoutput2')

Html.Label ('flower type')

Html.Div ([

Dcc.Dropdown (

Id='flowertype'

# options= [{'label':'setosa','value':'1'}]

# {'label':'versicolor','value':'2'}

# {'label':'virginnica','value':'3'}]

Options= [{'label': key,' value': value} for (key,value) in flowertype_dict.items ()]

Value='1')

])

], className= "dropdown")

Html.P ('Test multiple inputs and multiple outputs 1 Phantom multiple input multinputoutput1')

Html.P ('test multiple inputs, multiple outputs, 2purl multiple inputs, multiple outputs, multinputmultoutput2')

], id='mmap')

Html.Div ('mright',id='mright')

], id='main')

Html.Div ('Div footer', id='footer')]

, id='container')

# single input, single output

@ app.callback (Output ('city','children'), Input (' province','value'))

Def province2city (province):

Return province2city_ dict[province]

# multiple inputs, single output

@ app.callback (Output ('multinputsimpleoutput','children'), [Input (' province','value'), Input ('gender','value')])

Def province2city (province,gender):

Return province2city_] +'+ gender

# multiple inputs, single output, allow the same input parameters, return different output parameters; the same output parameters will report an error

@ app.callback (Output ('multinputsimpleoutput2','children'), [Input (' province','value'), Input ('gender','value')])

Def province2city (province,gender):

Return province2city_ returns [parameters] +''+ gender+' to different parameters'

# multiple inputs, multiple outputs

@ app.callback ([Output ('multinputmultoutput1','children'), Output (' multinputmultoutput2','children')], [Input ('province','value'), Input (' gender','value'), Input ('flowertype','value')])

Def province2city (province,gender,flowertype):

Flowtypename=list (flowertype_dict.keys ()) [list (flowertype_dict.values ()) .index (flowertype)]

After reading the above content in return province2city_ visualization +''+ gender,flowtypename, do you have any further understanding of how to use the callback of Python visual Dash tool? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Multiple output input parameters Sichuan Sichuan testing different same content Guangdong Guangdong Shaanxi Shaanxi methods of use tools methods visualization functions single Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology OPPO Reno Shulou Tech Info Huawei NVidia