# check out https://dash.plotly.com/ for documentation
# And check out https://py.cafe/maartenbreddels for more examples
from dash import Dash, Input, Output, callback, dcc, html
from dash_bootstrap_templates import load_figure_template
import dash_bootstrap_components as dbc
dbc_css = "https://cdn.jsdelivr.net/gh/AnnMarieW/dash-bootstrap-templates/dbc.min.css"
# Set the initial value to all possible selections
risk_counts = df['ID Risk'].value_counts()
# Convert Series to a DataFrame and set the index
risk_counts = risk_counts.reset_index()
# Rename the columns for clarity
risk_counts.columns = ['ID Risk', 'Solutions count']
initial_value = risk_counts['ID Risk'].sort_values(ascending = True).unique().tolist()
#Build the app
load_figure_template("DARKLY")
app = Dash(__name__, external_stylesheets=[dbc.themes.DARKLY, dbc_css])
app.layout = html.Div([
dcc.Dropdown(
id="filter",
options=risk_counts['ID Risk'].sort_values(ascending = True),
value=initial_value,
multi=True,
className="dbc"
),
dcc.Graph(id="graph"),
])
@app.callback(
Output('graph', 'figure'),
Input("filter", "value"),
)
def risky(options):
filtered_data = risk_counts.query("`ID Risk` in @options")
fig = px.bar(
filtered_data,
y='ID Risk', # Assuming this is your x-axis
x='Solutions count', # Assuming this is your y-axis
title="Solutions per risk",
color = 'Solutions count',
color_continuous_scale=px.colors.sequential.BuGn[::-1]).update_layout(width=1080, height=600,
title = {"x": .4,"y": .90},
coloraxis_colorbar= dict(
thicknessmode="pixels",
thickness=20,
dtick=5,
#ticksuffix=" points",
#title="Math Score"
))
fig.update_yaxes(autorange="reversed")
fig.update_layout(template='plotly_dark')
fig.update_xaxes(showgrid=False)
return fig