jimmybow / visdcc

Dash Core Components for Visualization.
MIT License
144 stars 18 forks source link

Trying use "selection" function as "clickToUse" function.... #2

Closed chinobing closed 6 years ago

chinobing commented 6 years ago

Here is how my web app looks like: 1

and here is the code:

      html.Div([visdcc.Network(id = 'net-holders', 
                     options = dict(height= '1000px', 
                                    width= '100%',
                                    physics={'barnesHut': {'avoidOverlap': 0.1}},         
                                    ))],  style={'padding-right':'10px','padding-left':'10px'}),  
blah blah blah .........

@app.callback(
    Output('net-holders', 'value'),
    [Input('net-holders', 'selection')])
def shareholders_addition(add):
    print( add)

here is the result: 2

My problem is that it wont show up the nodes and edges with corresponding names or ID when I select the nodes on the network? Do you know why?

chinobing commented 6 years ago

my bad. It works like a charm!

chinobing commented 6 years ago

Now I encounter another issue. The graph will be reset whenever I select a node.

      html.Div([visdcc.Network(id = 'net-holders', 
                     selection = {'nodes':[], 'edges':[]},         
                     options = dict(height= '1000px', 
                                    width= '100%',
                                    physics={'barnesHut': {'avoidOverlap': 0.1}},         
                                    ))],  style={'padding-right':'10px','padding-left':'10px'}),  

@app.callback(
    Output('net-holders', 'data'),
    [Input('stock-ticker', 'value'),
     Input('net-holders', 'selection')])
def shareholders_vis(ticker,select):
    data = {} 
    data_nodes = [] 
    data_edges = []    

    data={'nodes':data_nodes,
          'edges':data_edges}

    return data

But what if I put the data_nodes = [] and data_edges = [] outside the def shareholders_visfunction, It will be considered as global variable in DASH and it works. But it wont reset at all as I refresh my browser.

data = {} 
data_nodes = [] 
data_edges = []    
@app.callback(
    Output('net-holders', 'data'),
    [Input('stock-ticker', 'value'),
     Input('net-holders', 'selection')])
def shareholders_vis(ticker,select):

    data={'nodes':data_nodes,
          'edges':data_edges}

    return data