简体   繁体   English

Dash_table:SyntaxError:位置参数跟随关键字参数

[英]Dash_table: SyntaxError: positional argument follows keyword argument

I want to build a network using dash.我想使用破折号建立一个网络。

I have this data frame (called final_net):我有这个数据框(称为final_net):

   Entrez Gene Interactor A  Entrez Gene Interactor B
0                      6840                      7431
1                      6640                      5217
2                       823                      7431
3                     57019                     57019

If I convert that data frame to this kind of list:如果我将该数据框转换为这种列表:

dash_elements = []

for index,i in final_net.iterrows():
    dict1 = {}
    dict2 = {}
    dict1['data'] = dict2
    dict2['id'] = str(i[0])
    dict2['label'] = str(i[0])
    
    dict3 = {}
    dict1['data'] = dict3
    dict3['id'] = str(i[1])
    dict3['label'] = str(i[1])
    
    final_dict2 = {}
    final_dict3 = {}
    final_dict2['data'] = dict2
    final_dict3['data'] = dict3
    
    dash_elements.append(final_dict2)
    dash_elements.append(final_dict3)
    
  
    dict4 = {}
    final_dict4 = {}
    final_dict4['data'] = dict4
    dict4['source'] = str(i[0])
    dict4['target'] = str(i[1])
    dash_elements.append(final_dict4)
    

print(dash_elements)

And then read the data into dash like this:然后像这样将数据读入破折号:

import dash
import dash_core_components as dcc
from dash import html
import dash_cytoscape as cyto
from dash.dependencies import Input, Output
import plotly.express as px

app = dash.Dash(__name__)

app.layout = html.Div([
    html.P("Dash Cytoscape:"),
    cyto.Cytoscape(
        id='cytoscape',
        elements = dash_elements,
        layout={'name': 'breadthfirst'},
        style={'width': '1000px', 'height': '1000px'}
    )
])

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

A network is generated as expected.网络按预期生成。

I'm wondering if this could be done more elegantly by reading the data frame directly into the network.我想知道这是否可以通过将数据帧直接读入网络来更优雅地完成。

I wanted to implement the answer here , so I wrote:我想在这里实现答案,所以我写道:

from dash import dash_table



dt_col_param = []
for col in final_net.columns:
    dt_col_param.append({"name": str(col), "id": str(col)})


import dash
import dash_core_components as dcc
from dash import html
import dash_cytoscape as cyto
from dash.dependencies import Input, Output
import plotly.express as px

app = dash.Dash(__name__)

app.layout = html.Div([
    html.P("Dash Cytoscape:"),
    cyto.Cytoscape(
        id='cytoscape',
        
       dash_table.DataTable(
        columns=dt_col_param,
        data=final_net.to_dict()),

        layout={'name': 'breadthfirst'},
        style={'width': '1000px', 'height': '1000px'}
    )
])

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

But it returns the error:但它返回错误:

 File "<ipython-input-93-2fb47236fbc6>", line 31
    dash_table.DataTable(
    ^
SyntaxError: positional argument follows keyword argument

And i don't understand what I'm doing wrong.我不明白我做错了什么。 Could someone explain/show me how to correct this please?有人可以解释/告诉我如何纠正这个吗?

Well for one, you forgot, as the error says, the keyword for the parameter (ie, "elements"):好吧,正如错误所说,您忘记了参数的关键字(即“元素”):

app.layout = html.Div(
    [
        html.P("Dash Cytoscape:"),
        cyto.Cytoscape(
            id="cytoscape",
            elements=dash_table.DataTable(
                columns=dt_col_param, data=final_net.to_dict()
            ),
            layout={"name": "breadthfirst"},
            style={"width": "1000px", "height": "1000px"},
        ),
    ]
)

But that won't quite work either because that's not valid input for elements for the cyto.Cytoscape object — which requires但这也不太奏效,因为这不是cyto.Cytoscape对象elements的有效输入——这需要

"A list of dictionaries representing the elements of the networks." “代表网络元素的字典列表。”

If I have time I will come back to this & provide a more complete answer but hopefully this might be enough direction to help get you on your way to realize how to implement....如果我有时间,我会回到这个问题并提供更完整的答案,但希望这可能足以帮助您了解如何实施....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SyntaxError:位置参数跟随关键字参数 - SyntaxError: positional argument follows keyword argument Python celery任务画布:SyntaxError:位置参数紧跟关键字参数 - Python celery task canvas: SyntaxError: positional argument follows keyword argument 未能更正:此错误 SyntaxError:位置参数跟随关键字参数 - failed to correct : this error SyntaxError: positional argument follows keyword argument SyntaxError:位置参数遵循 CNN model 中的关键字参数 - SyntaxError: positional argument follows keyword argument in CNN model 语法错误:位置参数跟在关键字参数之后。 如何绕过它? - SyntaxError: positional argument follows keyword argument. How to bypass it? 位置参数跟随带破折号python的关键字参数图形 - positional argument follows keyword argument graphics with dash python 语法错误:位置参数跟随关键字参数 [discord.py] - SyntaxError: positional argument follows keyword argument [discord.py] 对networkx失败:SyntaxError:关键字关键字后跟位置参数 - failed to networkx: SyntaxError: positional argument follows keyword argument 我该如何解决 SyntaxError:位置参数跟随关键字参数 - How can I slove SyntaxError: positional argument follows keyword argument 什么是关键字关键字后面的位置参数? - What is positional argument follows keyword argument?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM