【发布时间】:2020-11-11 14:30:10
【问题描述】:
我一直在尝试从 python-Dash 应用程序的点击事件中返回“href”值。下面是我的代码 sn-p:
import dash
import dash_html_components as html
from dash.dependencies import Input, Output, State
app = dash.Dash(
__name__,
meta_tags=[{"name": "viewport", "content": "width=device-width, initial-scale=1"}],
)
def make_table(df, val):
table = []
for index, row in df.iterrows():
rows = []
html.Td([
html.Div([row["col1"]]),
html.A(id = 'link',href=row["file-link"], children=row["link-name"], target="_blank"),
])
table.append(html.Tr(rows))
return table
app.layout = html.Div([
html.Table(
id="table-element",
className="table__container",
)
],
className="six columns",
),
@app.callback(
Output("link", 'pathname'),
[Input('link', 'n_clicks')],
[State('link', 'href')]
)
def open_link(n_clicks, href):
enable_open_link(href) #enable_open_link function takes in the href string value (a local filesystem link) and opens it up in a new window.
@app.callback(
Output("table-element", 'children'),
[Input("input-1-submit", 'n_submit')],
[State('input-1-submit', 'value')]
)
def update_output(ns1,val):
table = make_table(df,val)
return table
此代码在某种程度上可以工作,即它确实返回一个 href 值,但不是我单击的那个。它总是返回存储在 html 表中的最后一个 href 值。
当我点击链接时,有没有办法获取 href 值? 我知道我可以使用 Jquery 来获取正确的 href 值……但我没有找到将 javascript 集成到回调函数中的方法。
【问题讨论】:
标签: python python-3.x href plotly-dash