The sample code for this article has been uploaded to my
Github
Warehouse:/CNFeffery/dash-masterGitee synchronization repository address:/cnfeffery/dash-master
Hello everyone I'm Mr. Faye, last weekDash
Posted.2.18.0
The new version, which was released today, can bestabiliseapplied2.18.1
Versions (since ancient times).1
version is the most stable ✌), today's post will address the2.18.1
A brief description of the issues that have been fixed and adjustments that have been made in the stabilized version.
The terminal executes the following command to set theDash
Upgrade to the latest version:
pip install dash -U
1 Fixed an issue where callbacks returning a single no_update for batch control did not work
exist2.18.0
Previous versions of the program were targeted at orchestrating multipleOutput
role's callback function, if we want to add a callback function to thecertain conditionsUnder the branch.abolishThis callback triggers a callback on thepossessOutput
role ofupdateThe common way to do this is to directlyreturn dash.no_update
Here's a singledash.no_update
It is possible to quickly and directly summarize allOutput
of not updating.
As a simple example, we trigger the update of 3 different target contents by the click of a button and theCancel update when the number of clicks is even, in the previous2.18.0
version, this shortcut write triggers the error shown below:
2.18.1
This was fixed in the release, and you can see that the functionality is now normal, i.e., the content is only updated when there is an odd number of clicks:
Complete code for this example:
import dash
from dash import html
import feffery_antd_components as fac
from import Input, Output
from feffery_dash_utils.style_utils import style
app = (__name__)
= (
[
(
[
f"Dashreleases: {dash.__version__}",
("Click me to try it.", , type="primary"),
(),
(),
(),
],
direction="vertical",
align="center",
)
],
style=style(padding=50),
)
@(
[Output(f"demo-output{i}", "children") for i in range(1, 4)],
Input("demo-button", "nClicks"),
prevent_initial_call=True,
)
def demo_callback(nClicks):
# only innClicksTriggered by an odd number
if nClicks % 2 == 1:
return (
f"nClicks: {nClicks}",
f"nClicks x 2: {nClicks*2}",
f"nClicks x 3: {nClicks*3}",
)
# Not updating anything
return dash.no_update
if __name__ == "__main__":
(debug=True)
2 Fixed exceptions in global/local callback function error handling mechanism + dictionaryized role orchestration
What's New in Dash 2.18In the article we introduced theDash
through (a gap)2.18.0
Beginning of the newGlobal/Local Callback Error Handling MechanismHowever, this property is not as strong when combined withCallback Function Dictionary Role OrchestrationIf the callback function in the example above is transformed into a dictionary-orchestrated form, it will function abnormally, as in the example above:
# here areon_errorSimply write an anonymous function to illustrate
app = (__name__, on_error=lambda e: print(e))
...
@(
output=dict(
demo_output1=Output("demo-output1", "children"),
demo_output2=Output("demo-output2", "children"),
demo_output3=Output("demo-output3", "children"),
),
inputs=dict(nClicks=Input("demo-button", "nClicks")),
prevent_initial_call=True,
)
def demo_callback(nClicks):
# only innClicksTriggered by an odd number
if nClicks % 2 == 1:
return dict(
demo_output1=f"nClicks: {nClicks}",
demo_output2=f"nClicks x 2: {nClicks*2}",
demo_output3=f"nClicks x 3: {nClicks*3}",
)
# Intentional triggering of an error
raise Exception("Custom Errors")
before2.18.0
version, error handling meets dictionaryized role scheduling would be redundant:
as well as2.18.1
In the example, this issue is effectively fixed, and as you can see, the error is captured properly in the example:
3 Begin deprecating the old run_server() method
Dash
Early start applications areapp.run_server()
The back has been added to the more recommended()
way. And from the2.18.1
Starting with the release, the formalization of theapp.run_server()
mark sth. asAbandonment of methodsand will be in the futureDash
This method is officially removed in version 3.0, and everyone is unified to replace it with the()
That's enough.
In addition to this, the update also includes an update to the()
hit the nail on the headplugins
、long_callback_manager
Parameters are marked as deprecated, for a full description of the update move to/plotly/dash/releases/tag/v2.18.1
。
This is what this article is all about, forDash
If you are interested in application development, please feel free to add the micro-signalCNFeffery
If you want to join us, please note "dash learning" to join our technical exchange group, and we will grow together.