Open url when a point on a graph is clicked

What I am trying to do is basically the same as in the issue here: Open url in new tab when chart is clicked on, but instead of using JavaScript I would like to do this using Python inside of a Dash app. Has anyone gotten something like this to work in Python?

1 Like

I don’t think this is possible with the existing components. dcc.Location can be used to edit the existing page’s location but it can’t be used to create a new tab. Your options are:
Option 1 - Create your own component that wraps window.open (https://dash.plot.ly/plugins)
Option 2 - Embed the page you want to open as an html.Iframe and update the src property of that Iframe whenever the dcc.Graph.clickData property changes
Option 3 - Fork the dcc.Graph component and add a custom click handler

1 Like

Option 4 - Add text annotations to points of interest: Time series plot with links to points of interest

1 Like

Has this been added in the meantime?

it has not, but it’s still a good idea!

Has this been added in the meantime?

This is a bit of a hack, and probably has its limitations, but this kind of thing does work for adding some hyperlinked text to a figure:

def _add_trace_label(fig, x=0.0, label="", y=0.0, hyperlink=None, xmode="date"):
    "Add a label to a plot"
    hlinkedtext = f'<a href="{hyperlink}">{label}</a>' if hyperlink else label
    fig.add_trace(go.Scatter(x = [x], y=[y], 
                                name=label, legendgroup=label,
                                mode="text", text=hlinkedtext,
                                ))