Open
Description
Enable more comprehensive type hinting of dash callback methods by exposing dash._callback.NoUpdate
.
Given callback()
and clientside_callback()
are already imported up, is there any reason not to also expose NoUpdate
?
A Minimal Dash App with comprehensive python typing:
# import NoUpdate alongside any other top-level import
from dash import Dash, NoUpdate, html, dcc, callback, Output, Input
import plotly.express as px
import pandas as pd
# TYPE_CHECKING block
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from plotly.graph_objects import Figure
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder_unfiltered.csv')
app = Dash(__name__)
app.layout = html.Div([
html.H1(children='Title of Dash App', style={'textAlign':'center'}),
dcc.Dropdown(df.country.unique(), 'Canada', id='dropdown-selection'),
dcc.Graph(id='graph-content')
])
@callback(
Output('graph-content', 'figure'),
Input('dropdown-selection', 'value')
)
def update_graph(value: str | None) -> Figure | NoUpdate: # Complete Input and Output typing, no room for error
dff = df[df.country==value]
return px.line(dff, x='year', y='pop')
if __name__ == '__main__':
app.run(debug=True)