Skip to content

Third design iteration #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 7, 2021
Merged

Third design iteration #8

merged 5 commits into from
Feb 7, 2021

Conversation

jonmmease
Copy link
Contributor

This PR contains another round of updates, cleanup, and refactoring.

Highlights:

Plugin

Introduces a dash app plugin that customizes the behavior of app.callback, rather than requiring the use of dx.callback. (Closes #4)

import dash
import dash_express as dx
app = dash.Dash(__name__, plugins=[dx.Plugin()])

Compatibility

Full backward compatibility with Dash 1. The new Dash Express features are only available when providing @app.callback with the input/state/output keyword arguments, but regular dependency objects are now accepted as positional arguments again.

Remove ComponentProps

Removes the component.props[...] syntax and the ComponentProps class. Instead, a new props argument is added to dx.arg. So now, to customize the component properties you do

dx.arg(dcc.DatePickerRange(), props=("start_date", "end_date"), ...)

instead of

dx.arg(dcc.DatePickerRange().props[("start_date", "end_date")], ...)

It avoids introducing an additional class, and it provides a place (arg) to document that the default value is "value". This is a proposed resolution of #6.

Default argument kind

The default value of kind in dx.arg is now determined by whether the value is passed in the input or state keyword argument. This argument can be overridden by explicitly providing a value to the dx.arg constructor. This makes it possible to define the "manual" workflow more easily.

Instead of:

@app.callback(
    input=dict(
        fun=dx.arg(["sin", "cos", "exp"], label="Function", kind="state"),
        figure_title=dx.arg("Initial Title", label="Figure Title", kind="state"),
        phase=dx.arg((1, 10), label="Phase", kind="state"),
        amplitude=dx.arg((1, 10), label="Amplitude", kind="state"),
        n_clicks=dx.arg(html.Button("Update"), props="n_clicks")
    ),
)

All of the components specifications can be passed to the state keyword argument, and the button specified as kind=input so that it is treated as input.

@app.callback(
    state=dict(
        fun=dx.arg(["sin", "cos", "exp"], label="Function"),
        figure_title=dx.arg("Initial Title", label="Figure Title"),
        phase=dx.arg((1, 10), label="Phase"),
        amplitude=dx.arg((1, 10), label="Amplitude"),
        n_clicks=dx.arg(html.Button("Update"), props="n_clicks", kind="input")
    ),
)

Documentation and Demos

The DOCUMENTATION.md and associated demos have been updated with these changes

 - Get ride of ComponentProps and component._props accessor.
 - Move props specification to dx.arg()
 - Improved backward compatibility with app.callback from Dash 1.
 - Uses plugin to customize behavior of app.callback rather than dx.callback(app, ...).
@jonmmease jonmmease merged commit 13c1dbe into main Feb 7, 2021
@jonmmease jonmmease deleted the v3 branch February 7, 2021 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DX as a plugin?
1 participant