There are several similar questions out there that I will reference in this, but I have a Dash DataTable
with a column that I would like to make a clickable hyperlink. The table essentially looks like so:
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
Without the hyperlinks, I am creating the table through a Pandas dataframe and the Data and Column references for Dash DataTable
like this:
# works fine
searchFrame = searchFrame.drop(columns=['ContentNoStop'])
columns = [{'name': col, 'id': col} for col in searchFrame.columns]
The links are created via:
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)
Now, following this question from Plotly forums, I edited to fit mine:
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' }
],
]
Directly copying that code throws a Syntax Error: Invalid Syntax
. So, I edited to:
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' }
]]
However, this throws a raise IndexingError("Too many indexers") pandas.core.indexing.IndexingError: Too many indexers
Using this SO question, I did the following which also threw the Too many indexers
. The other answer on that question I tried as well (below) threw 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' }
]]
What am I doing wrong here? I feel like it should not be super complicated to create links for these. Also, you will be my forever hero if you can accommodate for multiple links in some rows.