Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬Register for the Oct 27 webinar.

Return 'href' value on a click event


I have been trying to return the ‘href’ value from click event. Below is my code snippet:

import dash
import dash_html_components as html
from dash.dependencies import Input, Output, State

app = dash.Dash(
    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.A(id = 'link',href=row["file-link"], children=row["link-name"], target="_blank"),

    return table

app.layout = html.Div([
                        className="six columns",

    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 and opens it up in a new window.

    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

The code works upto some extent i.e. it does returns a href value, but not the one I click. Always seem to be returning the last href value stored inside the html table.

Is there a way to fetch the href value when I click on the link?
I know I can use Jquery to fetch the correct href value… but I didn’t find a way to integrate javascript within the call-back function.