✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Python callback to javascript event

Hi dash team,

I have created custom react components that implement a drag-n-drop interaction mode.

In essence, one component (the source) can be dragged and dropped on another component (the destination) and self identify and say “Hey, I’m a component of type X”.

I would like to be able to let Python know that this interaction took place so on the Python side I can respond by:

  • Adding a new child component inside a div
  • Adding a new trace on a chart
  • Adding a new column to a table, etc.

Is there a way to register dash callbacks that fire on javascript events (like the “drop” event I mentioned above)?

Because I’m writing these as custom react components I feel like it should be possible, but I’m having a hard time seeing the cleanest way to do this.


Cool idea! Take a look at how dcc.Graph handles plotly.js events like click, turning this into clickData source code

Depending on what kind of data you expect to have, it might also be worthwhile to add a counter property like n_clicks as the html components (and some dcc components) have. The main case this could be useful is if it would be possible to have the same event data twice in a row, because then the event data property would not change and thus the callback wouldn’t fire. source code

1 Like

Hi, you can try visdcc.Run_js, it allows you run javascript in callback .:laughing:

@jimmybow thanks for this, I’ve implemented it to do some formatting on a dash_daq object and it works great!