【发布时间】:2021-12-02 19:37:38
【问题描述】:
有几个类似的问题我将在此引用,但我有一个 Dash DataTable 与一个列,我想创建一个可点击的超链接。该表基本上如下所示:
Date Ticket ID Work Order Link (s)
2018-08-30 22:52:25 1444008 119846184 google.com/woNum=119846184
2021-09-29 13:33:49 1724734 122445397, 122441551 google.com/woNum=122445397, google.com/woNum=122441551
没有超链接,我通过 Pandas 数据框和 Dash DataTable 的数据和列引用创建表,如下所示:
# works fine
searchFrame = searchFrame.drop(columns=['ContentNoStop'])
columns = [{'name': col, 'id': col} for col in searchFrame.columns]
链接是通过以下方式创建的:
woLink = r'http://corp.com/uniqueid='
df['WO Link'] = df['Work Order'].str.replace('(\d+)', rf'{woLink}\1')
crLink = r'http://corp.com/uniqueid='
df['Ticket Link'] = crLink + df['Ticket ID'].astype(str)
现在,在 Plotly 论坛的 this question 之后,我进行了编辑以适合我的情况:
columns = [
{'name': col, 'id': col}
for col in searchFrame.loc[
:,
[
'Reported Date', 'Site','Ticket ID', 'Ticket Link', 'Work Order',\
'Score', 'Level', 'First', 'Last', 'Department', \
'Detection', 'Code', 'Content', 'Description', 'Owner', 'Owner Group', 'Document ID'
], { "name": "WO Link", "id": "WO Link", 'type': 'text', "presentation" :'markdown' }
],
]
直接复制该代码会引发Syntax Error: Invalid Syntax。所以,我编辑为:
columns = [
{'name': col, 'id': col}
for col in searchFrame.loc[
:,
[
'Reported Date', 'Site','Ticket ID', 'Ticket Link', 'Work Order',\
'Score', 'Level', 'First', 'Last', 'Department', \
'Detection', 'Code', 'Content', 'Description', 'Owner', 'Owner Group', 'Document ID'
], { "name": "WO Link", "id": "WO Link", 'type': 'text', "presentation" :'markdown' }
]]
但是,这会引发 raise IndexingError("Too many indexers") pandas.core.indexing.IndexingError: Too many indexers
使用this SO question,我做了以下也抛出了Too many indexers。我也尝试过的那个问题的另一个答案(如下)抛出了TypeError: unhashable type: 'slice'
idx = pd.IndexSlice
columns = [
{'name': col, 'id': col}
for col in searchFrame.loc[idx[
:,
[
'Reported Date', 'Site','Ticket ID', 'Ticket Link', 'Work Order',\
'Score', 'Level', 'First', 'Last', 'Department', \
'Detection', 'Code', 'Content', 'Description', 'Owner', 'Owner Group', 'Document ID'
], { "name": "WO Link", "id": "WO Link", 'type': 'text', "presentation" :'markdown' }
], :]
]
columns = [
{'name': col, 'id': col}
for col in searchFrame.loc(axis=0)[
:,
[
'Reported Date', 'Site','Ticket ID', 'Ticket Link', 'Work Order',\
'Score', 'Level', 'First', 'Last', 'Department', \
'Detection', 'Code', 'Content', 'Description', 'Owner', 'Owner Group', 'Document ID'
], { "name": "WO Link", "id": "WO Link", 'type': 'text', "presentation" :'markdown' }
]]
我在这里做错了什么?我觉得为这些创建链接应该不会太复杂。此外,如果您可以在某些行中容纳多个链接,您将是我永远的英雄。
【问题讨论】:
标签: python plotly-dash