Py.Cafe

vmuccion/

dash-adaptation-database

Adaptation analysis with Dash

DocsPricing
  • 2025-01-20_NCCS_Impact_P5_Klimakosten_Massnahmentabelle_CLEAN_Select_EN_20250206_onlyDatabase.xlsx
  • adaptation_database.py
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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