New to Plotly and dash and need help understanding why pie charts or dropdown menus are not displaying.
To give a basic rundown of how the application is supposed to work the user is supposed to go through the 4 dropdown menus and then based on what the user selects from the dropdown menus there will be 2 pie charts that display information from Status1 results on the left and Status2 results on the right.
For example, if the user selects application1,server1, DOT NET, and 5/21/2020 from the dropdown menus then the information I want to be able to see is the number of NA, NF, NR, or O results displayed in the piecharts to be able to compare the differences between Status1 and Status2.
Here is the code I have so far:
from dash import Input, Output, html, dcc, Dash
from dash.exceptions import PreventUpdate
import plotly.graph_objs as go
import pandas as pd
import dash_mantine_components as dmc
df = pd.read_csv("Documents/Coding Projects/test_app/Sample_Data.csv")
app = Dash(__name__)
app.layout = html.Div(
[
dmc.Group(
position="apart",
grow=True,
children=[
dcc.Dropdown(
id="applicationdropdown",
options=[
{"label": x, "value": x}
for x in df.sort_values("Application")["Application"].unique()
],
value="application1",
multi=False,
clearable=False,
),
dcc.Dropdown(
id="serverdropdown",
options=[
{"label": x, "value": x}
for x in df.sort_values("Server")["Server"].unique()
],
value="server1",
multi=False,
clearable=False,
),
dcc.Dropdown(
id="benchmarkdropdown",
options=[
{"label": x, "value": x}
for x in df.sort_values("Benchmark")["Benchmark"].unique()
],
value="DOT NET",
multi=False,
clearable=False,
),
dcc.Dropdown(
id="releasedatedropdown",
options=[
{"label": x, "value": x}
for x in df.sort_values("Release Date")["Release Date"].unique()
],
value="5/21/20",
multi=False,
clearable=False,
),
],
),
dmc.SimpleGrid(
cols=2,
children=[
html.Div(
[html.H4("Status Results 1"), dcc.Graph(id="piechart1")],
),
html.Div(
[html.H4("Status Results 2"), dcc.Graph(id="piechart2")],
),
],
),
]
)
@app.callback(
Output("piechart1", "figure"),
Output("piechart2", "figure"),
Input("applicationdropdown", "value"),
Input("serverdropdown", "value"),
Input("benchmarkdropdown", "value"),
Input("releasedatedropdown", "value"),
)
def update_graphs(
applicationdropdown, serverdropdown, benchmarkdropdown, releasedatedropdown
):
if (
applicationdropdown is None
or serverdropdown is None
or benchmarkdropdown is None
or releasedatedropdown is None
):
raise PreventUpdate
filtered_df = df.query(
"Application == @applicationdropdown"
"Server == @serverdropdown"
"Benchmark == @benchmarkdropdown"
"`Release Date` == @releasedatedropdown"
)[["Version1", "Version2"]]
version1_counts = filtered_df["Version1"].value_counts().reset_index()
fig1 = go.Figure(data=[go.Pie(labels=version1_counts.index, values=version1_counts.version1)])
if __name__ == '__main__':
app.run_server(debug=True)