I’m creating a dashboard that has numerous progress bars on them using the dbc.progress dash bootstrap components.
I would like to know if it is possible to be able to click on this progress bar component, which gets redirected to another page using the @app.callbacks. If not is there a way to do this with Javascript function.
You could listen for mouse events using the EventListener component. Here is a small example with a data table,
import dash_html_components as html
import dash_table
import pandas as pd
from dash import Dash
from dash.dependencies import Output, Input
from dash_extensions import EventListener
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv')
listen_prop = "srcElement.innerText"
app = Dash()
app.layout = html.Div([
# The EventListener components listens to events from children (or document, if no children are specified).
EventListener(id="el", events=[{"event": "click", "props": [listen_prop]}], children=[
dash_table.DataTable(
id='table',
columns=[{"name": i, "id": i} for i in df.columns],
data=df.to_dict('records'),
)
]),
# Containers for logging.
html.Div(id="event"), html.Div(id="n_events"),
])
@app.callback(Output("event", "children"), Input("el", "event"), prevent_initial_call=True)
def log_event(event):
return event[listen_prop]
if __name__ == '__main__':
app.run_server(port=7777)
Depending on your need, you might need to listen to a different prop. The component is available in dash-extensions==0.0.61rc3. I expect to push it to non-rc relatively soon.