[Feature Request] PreProcess and PostProcess Callback Hooks
Les mainteneurs répondent en général sous 2 jours
@BSd3v y travaille déjà.
Depuis le 9/10/2025.
Évaluation
Cette issue n'a pas encore été évaluée.
Description
I'd like to request PreProcess and PostProcess hooks to be used within the scope of a callback.
Essentially, this would allow developers to intercept specific things before and after a callback function is called. The PostProcess would be placed before the response was sent back to the client.
This could potentially solve issues like this: https://github.com/plotly/dash/issues/262
Here is an example of how this could potentially work, though the hooks wouldnt be inside the callbacks:
import dash
from dash import html, Input, Output, dcc, ctx
import time
server_side_stores = {}
def my_preprocess(args, kwargs, input_state_list):
# Log and update args with server-side store data if available
for i in range(len(args)):
if 'id' in input_state_list[i]:
store_id = input_state_list[i]['id']
if store_id in server_side_stores:
args[i] = server_side_stores[store_id]
return args, kwargs
def my_postprocess(output_list, response):
# Log and update server-side store with response data
for i in range(len(output_list)):
if 'id' in output_list[i]:
store_id = output_list[i]['id']
server_side_stores[store_id] = response[i]
response[i] = {"timestamp": time.time()}
return response
class MyStore(dcc.Store):
def __init__(self, id, data, *args, **kwargs):
server_side_stores[id] = data
timestamped_data = {"timestamp": time.time()}
super().__init__(id=id, data=timestamped_data, *args, **kwargs)
app = dash.Dash(__name__, suppress_callback_exceptions=True)
app.layout = html.Div(
[
MyStore(id="my-store", data={"key": "value"}),
dcc.Input(id="input", type="text"),
html.Div(id="output"),
],
style={"padding": 50},
)
@app.callback(
Output("output", "children"),
Input("my-store", "data"),
)
def update_input(store_data):
# Preprocess
args, kwargs = my_preprocess(
[store_data], {}, ctx.inputs_list+ctx.states_list
)
result = f"Original data: {args[0]}, Store timestamp: {store_data['timestamp']}"
return result
@app.callback(
Output("my-store", "data"),
Input("input", "value"),
prevent_initial_call=True,
)
def update_store(input_value):
# Postprocess
resp = my_postprocess([ctx.outputs_list], [{"key": input_value}])
return resp[0]
if __name__ == "__main__":
app.run(debug=True)
I recommend adding the hooks to the _callback.py in _initialize_context after the func_args, func_kwargs are set and in _prepare_response. With the currently displayed pattern, there could be some potential performance drawbacks, so we might need to look at streamlining how these are iterated.
This could also be narrowed down to only the callbacks that need to be transformed/augmented in place.
This could also be used to allow dataframes to be returned from a callback, data validation on the frontend, etc.
- Langage dominant
- Python
- Étoiles
- 24.4k
- Forks
- 2.3k
- Merge moyen
- 2 j 19 h
- PR mergées (30 j)
- 26
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de plotly/dash
-
P2 plotly-internal size: 1 task
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 2 jours
-
Extract graph schema validation into properly named testPeut-être pris @Nice6042 l’a pris il y a 60 jours. Ouvertegood first issue P3 size: 1 task
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
plotly/dash#3735 · 3 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
[BUG] dcc.Dropdown: hidden focus-target input is focusable inside aria-hidden and can overflow its wrapperPeut-être pris @KoolADE85 l’a pris il y a 8 jours. Ouvertebug P2 size: 1
Difficulté 4/5 3-5 jours Accessibilité débutants 56/100
plotly/dash#4042 · 3 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 2 jours
-
Linter/Type Checking ReplacementOuverteP3 plotly-internal size: 10+ task
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 30/100
plotly/dash#4040 · 3 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
Drop Python 3.9 SupportOuverteP2 plotly-internal size: 5 task
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
plotly/dash#4038 · 2 commentaires ·
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de plotly/dash
Issues similaires
-
python triage
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
microsoft/semantic-kernel#14590 ·
Les mainteneurs répondent en général sous 3 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
pinterest/pymemcache#662 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 Une demi-journée Accessibilité débutants 62/100
gnocchixyz/gnocchi#1527 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 64/100
tenstorrent/tt-model-manager#181 ·
Les mainteneurs répondent en général sous 1 jour