Hi @metma,
I’m not sure what you’re attempting to do, but maybe this can guide you:
Generate a link based on the value of the selected cell:
from dash import Dash, dash_table, callback, Input, Output, State
from dash.exceptions import PreventUpdate
app = Dash(__name__)
app.layout = dash_table.DataTable(
data=[
{'shop': 'Bakersfield', 'sales': 4, 'goal': 10},
{'shop': 'Berkeley', 'sales': 10, 'goal': 1},
{'shop': 'Big Bear Lake', 'sales': 5, 'goal': 4}
],
columns=[
{'id': 'shop', 'name': 'Store Location'},
{'id': 'sales', 'name': 'Sales Revenue'},
{'id': 'goal', 'name': 'Revenue Goal'},
],
# Style headers with a dotted underline to indicate a tooltip
style_data_conditional=[{
'if': {'column_id': 'shop'},
'textDecoration': 'underline',
'textDecorationStyle': 'dotted',
}],
tooltip_delay=0,
tooltip_duration=None,
id='data-table'
)
@callback(
[Output('data-table', 'tooltip_data')],
[Input('data-table', 'active_cell')],
[State('data-table', 'data')],
prevent_initial_call=True
)
def update_url(active_cell, data):
# use the value of the active cell to generate the URL output
selected_row = active_cell['row']
selected_col = active_cell['column_id']
data_val = data[selected_row][selected_col]
if data_val == 'Bakersfield':
return [[
{
'shop': {
'value': f'Row {selected_row} in "{selected_col}" column\n\n![Bakersfield]({app.get_relative_path("/assets/image.jpg")})',
'type': 'markdown'
}
}
]]
raise PreventUpdate
if __name__ == '__main__':
app.run_server(debug=True)
Define links using a list comprehension along with some data structure
from dash import Dash, dash_table, callback, Input, Output, State
from dash.exceptions import PreventUpdate
app = Dash(__name__)
# this could be in a DataFrame, Series, or any other data structure
img_paths_data = {
1: {'link': app.get_relative_path("/assets/image1.jpg"), 'alt_text': 'IMAGE 1', 'description': 'DESCRIPTION 1'},
2: {'link': app.get_relative_path("/assets/image2.jpg"), 'alt_text': 'IMAGE 2', 'description': 'DESCRIPTION 2'},
3: {'link': app.get_relative_path("/assets/image3.jpg"), 'alt_text': 'IMAGE 3', 'description': 'DESCRIPTION 3'},
}
app.layout = dash_table.DataTable(
data=[
{'shop': 'Bakersfield', 'sales': 4, 'goal': 10},
{'shop': 'Berkeley', 'sales': 10, 'goal': 1},
{'shop': 'Big Bear Lake', 'sales': 5, 'goal': 4}
],
columns=[
{'id': 'shop', 'name': 'Store Location'},
{'id': 'sales', 'name': 'Sales Revenue'},
{'id': 'goal', 'name': 'Revenue Goal'},
],
# Style headers with a dotted underline to indicate a tooltip
style_data_conditional=[{
'if': {'column_id': 'shop'},
'textDecoration': 'underline',
'textDecorationStyle': 'dotted',
}],
tooltip_data=[
{
'shop': {
'value': f"{img_data['description']}\n![{img_data['alt_text']}]({img_data['link']})",
'type': 'markdown'
}
}
for img_data in img_paths_data.values()
],
tooltip_delay=0,
tooltip_duration=None,
id='data-table'
)
if __name__ == '__main__':
app.run_server(debug=True)
You could adapt this to whatever your own use. If these don’t meet what you need, feel free to provide more information.