Location>code7788 >text

Dash 2.18.2 Update: Big Performance Improvements for Pattern Matching Callbacks

Popularity:429 ℃/2024-11-06 02:30:29

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. Fei, todayDashPosted.2.18.2The version update, although it is only a minor version update, some of the content involved is still very important, and I'm going to introduce it to you in today's post.

The terminal executes the following command to set theDashUpgrade to the latest version:

pip install dash -U

Pattern Matching Callback Function Performance Dramatically Improved

In previous releases, based on theALLPattern-matching constructed callback functions when the component involvedIt's a very large number.When the callback function is triggered, there is a noticeable lag.

As a simple example, we rendered the page with the1000A switching assembly that passesALLPattern matching callbacks, real-timestatisticiansthere arewhich (number)The switch is inshow (a ticket)state, before it was updated2.18.1Under the version, you can see that every time you operate the switch, it is accompanied by a noticeable lag:

And the update to2.18.2Afterward, it was so silky smooth 🥳:

The corresponding source code for the example is as follows:

import dash
from dash import html
import feffery_antd_components as fac
from feffery_dash_utils.style_utils import style
from import Input, Output, ALL

app = (__name__)

 = (
    [
        f"Dashreleases:{dash.__version__}",
        (
            (
                [
                    (
                        id={"type": "test-switch", "index": i}, checked=False
                    )
                    for i in range(1000)
                ],
                wrap=True,
            ),
            style=style(
                height=300, overflow="auto", padding=5, border="1px solid #bfbfbf"
            ),
        ),
        ("Number of switches opened:0", ),
    ],
    style=style(padding=50),
)

app.clientside_callback(
    "(checked_list) => `Number of switches opened:${checked_list.filter(Boolean).length}`",
    Output("test-output", "children"),
    Input({"type": "test-switch", "index": ALL}, "checked"),
    prevent_initial_call=True,
)

if __name__ == "__main__":
    (debug=True)

In addition to this, the release update also adds a new function to the regular callbacks corresponding to theContext addedcookiesheaderspathremoteoriginand other attributes, for a complete description of the update please go to/plotly/dash/releases/tag/v2.18.2


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.