
Plotly and Dash allow us to create interactive web dashboards with multiple visualizations and filtering controls. In this example, we build a dashboard containing four plots that update dynamically based on the selected experimental groups and anomaly status.
First, we load the dataset and initialize the Dash application:
df = pd.read_csv("../data/measurements.csv")
app = Dash(__name__)
We use html.Div() to organize the dashboard and dcc.Dropdown() to create filtering controls.
The first dropdown allows users to select experimental groups, while the second filters measurements by anomaly status.
dcc.Dropdown(
id="group",
options=[
{"label": g, "value": g}
for g in sorted(df["group"].unique())
],
value=list(df["group"].unique()),
multi=True
)
dcc.Dropdown(
id="anomaly",
options=[
{"label": "All measurements", "value": "all"},
{"label": "Normal", "value": "normal"},
{"label": "Anomalies only", "value": "anomaly"}
],
value="all",
clearable=False
)
The multi=True parameter allows selecting multiple experimental groups.
The dashboard contains four visualizations:
• Histogram – temperature distribution.
• Scatter plot – temperature versus pressure.
• Line plot – mean energy over time.
• 3D scatter plot – spatial distribution of measurements.
The dcc.Graph() component displays each visualization.
We use @app.callback() to connect the dropdown menus with all four plots:
@app.callback(
Output("histogram", "figure"),
Output("scatter", "figure"),
Output("time_series", "figure"),
Output("scatter_3d", "figure"),
Input("group", "value"),
Input("anomaly", "value")
)
The Input() components define which user interactions trigger the callback, while Output() specifies which plots are updated.
Inside update_dashboard() , we filter the original dataset according to the selected options:
filtered = df[df["group"].isin(groups)]
if anomaly == "normal":
filtered = filtered[~filtered["anomaly"]]
elif anomaly == "anomaly":
filtered = filtered[filtered["anomaly"]]
This ensures that all four visualizations use the same filtered dataset.
We use Plotly Express to generate four interactive charts:
• px.histogram() – displays temperature distribution for each experimental group.
• px.scatter() – shows the relationship between temperature and pressure, distinguishing anomalies using different symbols.
• px.line() – displays mean energy over time, grouped by experimental group.
• px.scatter_3d() – visualizes the spatial distribution of measurements in three dimensions, with colors representing temperature.
For the time series, measurements are grouped into time intervals of 0.5 units, and mean energy is calculated for each group.
We apply a consistent visual theme and adjust the margins of all plots:
for fig in [fig1, fig2, fig3, fig4]:
fig.update_layout(
template="plotly_white",
margin=dict(l=30, r=20, t=50, b=30)
)
return fig1, fig2, fig3, fig4
The callback returns all four updated figures whenever a dropdown selection changes.
Finally, we start the Dash server:
if __name__ == "__main__":
app.run(debug=True)
The dashboard can then be opened in a web browser using the local address displayed in the terminal.
In this example, we used:
• Dash() – initializes the web application.
• html.Div() – organizes the dashboard layout.
• dcc.Dropdown() – creates interactive filtering controls.
• dcc.Graph() – displays interactive charts.
• @app.callback() – connects user interactions with plot updates.
• plotly.express – generates interactive 2D and 3D visualizations.