I am trying to create a scatterplot with one dropdown selector and hope that the selector has the ability to chose multiple capsules and the default set at all capsules.
I understand the multi have to be first set to True, and the callback have to be adjusted to update the graph for each subsequent change or add in of capsule. I am having trouble finding a suitable way to change the code such that I can chose multiple capsule and even the whole dataset of capsules. I have also created a list of the unique capsule ID and use that as the dropdown so that is working.
Data looks like this.
Dash plotly looks this.
Code I run on pycharm.
import pandas as pd
import plotly.express as px # (version 4.7.0)
import plotly.graph_objects as go
import dash # (version 1.12.0) pip install dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
df = pd.read_csv("tcd vs rh.csv")
print(df)
capsuleID = df['Capsule_ID'].unique()
print(capsuleID)
capsuleID_names = list(capsuleID)
print(capsuleID_names)
app.layout = html.Div([
html.H1("Web Application Dashboards with Dash", style={'text-align': 'center'}),
dcc.Dropdown(id="capsule_select",
options=[{"label": capsuleID_names, "value": capsuleID_names} for capsuleID_names in capsuleID_names],
multi=True,
value=2100015,
style={'width': "40%"}
),
html.Div([
dcc.Graph(id="the_graph")
]),
])
# -----------------------------------------------------------
@app.callback(
Output('the_graph', 'figure'),
[Input('capsule_select', 'value')]
)
def update_graph(capsule_chosen):
dff = df[(df['Capsule_ID'] == capsule_chosen)] # filter all rows where capsule ID is the capsule ID selected
scatterplot = px.scatter(
data_frame=dff,
x="tcd",
y="humidity",
)
scatterplot.update_traces(textposition='top center')
return scatterplot
# ------------------------------------------------------------------------------
if __name__ == '__main__':
app.run_server(debug=True)

