I am trying to use the dash-draggable library (instead of rc-dock which is giving me problems) in my application. The content inside each draggable box is dynamic and can be rather large (plot with many data points). Now instead of passing the children down to the dash-draggable to append a new child onto it (can be 10s of MB of data being passed back and forth) I want to make use of dash-extensions OperatorTransform with OutputOperator to append to the list.
The example below shows that this is not working. If I use regular callbacks the layout object works well and i can set default width of 12 columns, but when i move to OutputOperator it does not seem to work. Below is working example modified from the dash-draggable library. @Emil do you have any ideas/suggestions why dash-extensions causes this issue?
import dash
from dash import dcc, Input, Output, State, html, ctx
from dash.exceptions import PreventUpdate
from dash_extensions.enrich import DashProxy, OperatorOutput, Operator, OperatorTransform
import dash_draggable
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = DashProxy(__name__,
transforms=[OperatorTransform()], external_stylesheets=external_stylesheets)
@app.callback(
Output("draggable", "layouts"),
Output("draggable", "children"),
# OperatorOutput("draggable", "children"),
Input("graph", "n_clicks"),
Input("slider", "n_clicks"),
State("draggable", "children"),
State("draggable", "layouts"),
)
def ddd (graph, slider, children, layouts):
layouts = layouts or {"lg": []}
children = children or []
if ctx.triggered_id is None:
raise PreventUpdate
if ctx.triggered_id == "graph":
id=f'graph-with-slider-{graph}'
new_item = dcc.Graph(
id=id,
responsive=True,
style={
"width":"100%",
"height":"100%",
})
layouts["lg"].append(dict(w=12, h=10, x=0, y=0, i=id))
if ctx.triggered_id == "slider":
id=f'year-slider-{slider}'
years = [2000 + r for r in range(0, 10)]
new_item = dcc.Slider(
id=id,
min=min(years),
max=max(years),
value=min(years),
marks={str(year): str(year) for year in years},
step=None)
layouts["lg"].append(dict(w=12, h=2, x=0, y=0,i=id))
children.append(new_item)
# return layouts, Operator().list.append(new_item)
return layouts, children
app.layout = html.Div([
html.Button("graph", id="graph"),
html.Button("slider", id="slider"),
dash_draggable.ResponsiveGridLayout(
id='draggable',
clearSavedLayout=True,
children=[ ]
),
])
if __name__ == '__main__':
app.run_server(debug=True, port='5080')