Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Elements does not work with Clientside Callbacks #199

Open
Louiszk opened this issue Nov 21, 2023 · 0 comments
Open

Adding Elements does not work with Clientside Callbacks #199

Louiszk opened this issue Nov 21, 2023 · 0 comments

Comments

@Louiszk
Copy link

Louiszk commented Nov 21, 2023

MRE:

import dash
from dash import dcc, html,Input, Output, State, no_update
import dash_cytoscape as cyto

app = dash.Dash(__name__)

app.layout = html.Div([
    cyto.Cytoscape(
        id='cytoscape',
        elements=[
            {'data': {'id': 'node1', 'label':"node1"}, 'positions': {'x': 0, 'y': 0}}
        ],
        layout={'name': 'preset'},
        style={'width': '400px', 'height': '400px'}
    ),
    html.Button('Add Node', id='add-node-btn')
])


app.clientside_callback(
'''
function (nClicks, currentElements){
    if (!nClicks) {
        return dash_clientside.no_update;
    }
    let x=50;
    let y=100;
    let newNode = { 'data': { 'id': 'node2' }, 'position': { 'x': x, 'y': y } };
    currentElements.push(newNode);
    console.log(currentElements);

    return JSON.parse(JSON.stringify(currentElements));
}

''',
    Output('cytoscape', 'elements'),
    Input('add-node-btn', 'n_clicks'),
    State('cytoscape', 'elements'),
    prevent_initial_call=True
)

if __name__ == '__main__':
    app.run_server(debug=True)

Expected Results

Clientside Callbacks should be able to add elements.

Actual Results

It does not work.

Versions

Cytoscape 0.3.0
Dash 2,14.1

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

No branches or pull requests

1 participant