Location>code7788 >text

Dash 2.18.1, the stable version of Python web application developer, is here!

Popularity:203 ℃/2024-09-19 11:40:03

The sample code for this article has been uploaded to myGithubWarehouse:/CNFeffery/dash-master

Gitee synchronization repository address:/cnfeffery/dash-master

Hello everyone I'm Mr. Faye, last weekDashPosted.2.18.0The new version, which was released today, can bestabiliseapplied2.18.1Versions (since ancient times).1version is the most stable ✌), today's post will address the2.18.1A 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 theDashUpgrade 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.0Previous versions of the program were targeted at orchestrating multipleOutputrole's callback function, if we want to add a callback function to thecertain conditionsUnder the branch.abolishThis callback triggers a callback on thepossessOutputrole ofupdateThe common way to do this is to directlyreturn dash.no_updateHere's a singledash.no_updateIt is possible to quickly and directly summarize allOutputof 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.0version, this shortcut write triggers the error shown below:

2.18.1This 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 theDashthrough (a gap)2.18.0Beginning 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.0version, error handling meets dictionaryized role scheduling would be redundant:

as well as2.18.1In 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

DashEarly start applications areapp.run_server()The back has been added to the more recommended()way. And from the2.18.1Starting with the release, the formalization of theapp.run_server()mark sth. asAbandonment of methodsand will be in the futureDashThis 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 headpluginslong_callback_managerParameters 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, forDashIf you are interested in application development, please feel free to add the micro-signalCNFefferyIf you want to join us, please note "dash learning" to join our technical exchange group, and we will grow together.