Skip to content

[4.2] Persistent callbacks#3771

Open
T4rk1n wants to merge 3 commits intov4.2from
persistent-callbacks
Open

[4.2] Persistent callbacks#3771
T4rk1n wants to merge 3 commits intov4.2from
persistent-callbacks

Conversation

@T4rk1n
Copy link
Copy Markdown
Contributor

@T4rk1n T4rk1n commented May 8, 2026

This PR adds support for:

  1. Persistent callbacks - Callbacks with persistent=True don't show "Updating..." in the browser title while running
  2. No-output callbacks - Callbacks without outputs that fire on initial load, fixes [BUG] no output callbacks doesn't trigger as initial callback. #3770
  3. No-input callbacks - Callbacks without inputs (only State) that fire on initial load, resolves [Feature Request] allow for callbacks without Inputs #3411
  4. No-input no-output callbacks - Callbacks with neither inputs nor outputs that fire once on initial load

Examples

Persistent callback without inputs/outputs

import asyncio                                                                                                                                                                                                 
from dash import Dash, html, callback, set_props                                                                                                                                                               
                                                                                                                                                                                                               
app = Dash(backend="fastapi", websocket_callbacks=True)                                                                                                                                                        
                                                                                                                                                                                                               
app.layout = html.Div([                                                                                                                                                                                        
    html.Div(id="counter", children="0"),                                                                                                                                                                      
])                                                                                                                                                                                                             
                                                                                                                                                                                                               
@callback(persistent=True)                                                                                                                                                                                     
async def continuous_updates():                                                                                                                                                                                
    # Fires once on load, runs forever without showing "Updating..." title                                                                                                                                     
    n = 0                                                                                                                                                                                                      
    while True:                                                                                                                                                                                                
        set_props("counter", {"children": str(n)})                                                                                                                                                             
        n += 1                                                                                                                                                                                                 
        await asyncio.sleep(1)                                                                                                                                                                                 
                                                                                                                                                                                                               
if __name__ == "__main__":                                                                                                                                                                                     
    app.run() 

No-input callback (fires on initial load)

from dash import Dash, html, Output, State, callback                                                                                                                                                           
                                                                                                                                                                                                               
app = Dash()                                                                                                                                                                                                   
                                                                                                                                                                                                               
app.layout = html.Div([                                                                                                                                                                                        
    dcc.Store(id="config", data={"theme": "dark"}),                                                                                                                                                            
    html.Div(id="output"),                                                                                                                                                                                     
])                                                                                                                                                                                                             
                                                                                                                                                                                                               
@callback(                                                                                                                                                                                                     
    Output("output", "children"),                                                                                                                                                                              
    State("config", "data"),                                                                                                                                                                                   
)                                                                                                                                                                                                              
def initialize_from_config(config):                                                                                                                                                                            
    # Fires once on page load with State values                                                                                                                                                                
    return f"Theme: {config['theme']}"                                                                                                                                                                         
                                                                                                                                                                                                               
if __name__ == "__main__":                                                                                                                                                                                     
    app.run() 

No-input no-output callback (side-effect only)

from dash import Dash, html, callback                                                                                                                                                                          
                                                                                                                                                                                                                 
app = Dash()                                                                                                                                                                                                   
app.layout = html.Div([html.Div(id="output")])                                                                                                                                                                 
                                                                                                                                                                                                               
@callback()                                                                                                                                                                                                    
def log_page_load():                                                                                                                                                                                           
    # Fires once when page loads                                                                                                                                                                               
    print("Page loaded!")                                                                                                                                                                                      
    # Could log to database, initialize connections, etc.                                                                                                                                                      
                                                                                                                                                                                                               
if __name__ == "__main__":                                                                                                                                                                                     
    app.run() 

@T4rk1n T4rk1n changed the title ] Persistent callbacks [4.2] Persistent callbacks May 8, 2026
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.

1 participant