Hi @MonkeyChap
Returning an empty list works to remove elements. Here is an example:
Note- See also the section on adding and removing elements in the docs: Callbacks | Dash for Python Documentation | Plotly
import dash
from dash.dependencies import Input, Output, State
import dash_cytoscape as cyto
import dash_html_components as html
app = dash.Dash(__name__)
app.layout = html.Div(
[
html.H1("My Cytoscape"),
html.Button("toggle elements", id="button"),
cyto.Cytoscape(
id="cytoscape-two-nodes",
layout={"name": "preset"},
style={"width": "100%", "height": "400px"},
elements=[],
),
]
)
@app.callback(
Output("cytoscape-two-nodes", "elements"),
Input("button", "n_clicks"),
State("cytoscape-two-nodes", "elements"),
)
def update_output(n_clicks, el):
elements = [
{"data": {"id": "one", "label": "Node 1"}, "position": {"x": 75, "y": 75}},
{"data": {"id": "two", "label": "Node 2"}, "position": {"x": 200, "y": 200}},
{"data": {"source": "one", "target": "two"}},
]
return elements if el == [] else []
if __name__ == "__main__":
app.run_server(debug=True)
