【问题标题】:Working with Dash Cytoscape from data frame从数据框中使用 Dash Cytoscape
【发布时间】:2021-03-14 10:44:23
【问题描述】:

比方说,我有下表。

df

source    target     Weight
A            B        10
A            C        8
C            F        8
B            F        6
F            D        6
B            E        4

我能够设法使用networkx 库来绘制它。而且我也想尝试使用Dash Cytoscope 组件。

我尝试了以下方法。但还没有成功。

app.layout = html.Div([
    html.Div([
 
        cyto.Cytoscape(
            id='org-chart',
            autoungrabify=True,
            minZoom=0.2,
            maxZoom=1,
            layout={'name': 'breadthfirst'},

            style={'width': '100%', 'height': '500px'},
            elements=
                [
                    # Nodes elements
                    {'data': {'id': x, 'label': x}} for x in df.name
                ]
                +
                [
                    # Edge elements
                    {'data': {'source': df['source'], 'target': df['target']}},
                    
                ]
        )
    ], className='six columns'),

    html.Div([
        html.Div(id='empty-div', children='')
    ],className='one column'),

], className='row')

感谢任何帮助。

【问题讨论】:

    标签: python networkx plotly-dash cytoscape


    【解决方案1】:

    问题是您尝试使用整个数据框列而不是迭代它来定义边缘(就像您对节点所做的那样)。你试过下面的代码吗?

    edges = [{'data': {'source': x, 'target': y}} for x,y in zip(df.source,df.target)]
    

    【讨论】:

      猜你喜欢
      • 2022-11-04
      • 2022-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-08
      相关资源
      最近更新 更多