如何在 Dash 中使表格的单元格值超链接? (使用 Plotly、Dash、Pandas 等)
  VDvlWkTw2thq 2023年11月22日 25 0

要在 Dash 中使表格的单元格值超链接,您可以使用 dash_table.DataTable 组件和 Pandas 数据框。以下是一个基本示例代码,演示了如何将表格中的某些单元格值转换为超链接:

首先,确保已完成以下安装:

pip install dash
pip install pandas

然后,使用以下代码创建一个具有超链接单元格值的 Dash 应用:

import dash
import dash_html_components as html
import dash_table
import pandas as pd

app = dash.Dash(__name__)

# 创建一个示例数据框
data = {
    'Name': ['John', 'Jane', 'Tom'],
    'Age': [25, 30, 35],
    'Website': ['https://www.google.com', 'https://www.facebook.com', 'https://www.linkedin.com']
}
df = pd.DataFrame(data)

# 将“Website”列中的值转换为超链接
df['Website'] = df['Website'].apply(lambda x: html.A('Website', href=x))

app.layout = dash_table.DataTable(
    id='table',
    columns=[{"name": i, "id": i} for i in df.columns],
    data=df.to_dict('records')
)

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

上述代码将创建一个 Dash 应用,其中包含一个表格。在示例数据框中,“Website”列的值将被转换为超链接,链接地址为列中对应的 URL。在这个示例中,我们使用了 Dash 的 HTML 组件 html.A 来创建超链接。

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月22日 0

暂无评论

推荐阅读
  NHaurzrhyr04   2023年12月23日   103   0   0 htmljQueryhtmljQuery
  BEOpup9HILHT   2023年12月23日   75   0   0 htmljQueryhtmljQuery
VDvlWkTw2thq