I am creating a dashboard using Flask and Dash. The dashboard has all its navigation menus, header and footer in Flask. In the content section I have iframed my Dash application.
In the iframe I have populated a datatable. I want a functionality where when I click on certain cell of the datatable, I want to navigate to another route. Everything up until now is smooth.
The problem is : Upon clicking the cell, the new route populates in the same iframe. is there a way to exit the iframe and go to the route.
I tried that already. It isn’t working. The way I approached is, I check if the cell is active or not in the datatable. And if it is active /selected then I redirect it to another url.
The approach that you mentioned would work if the selected/active cell was an anchor tag or if it was any html element. I am not sure about it though.
Also, since I have added the src of my iframe as the route, I will have to specify some code in the route /dashboard to redirect it to another page
@app.callback(Output(‘firstlink’,‘href’),[Input(‘info_table’,‘active_cell’),Input(‘info_table’,‘data’)])
def navigate(active cell,data):
if selected_cell[‘row’]>-1: #Checked if the cell is active.
# If it is activ, do something with the data and return the path. Say /newpath
return newpath
`dcc.Location(id=‘firstlink’ ,refresh=True)
This works perfectly. However, the new route is called in the iframe itself.
Hope the information I have provided gives you the insight needed.
Ah I see, you’re doing it with a callback on a DataTable’s active_cell property that’s targeting the href of a dcc.Location component.
This idea is on the right track, but I think you might be running into a limitation of Dash. When using an anchor tag, you can set the target attribute to _parent to target the outer window context (as suggested in those Stack Overflow answers). But the dcc.Location component is stuck targeting the current window.location with no way of targeting window.parent.location (as you can see from the source code). Perhaps the dcc.Location component could be extended to have a target prop.