Py.Cafe

giselle.pomodor/

dash-makeup-shade-selector

Makeup Shade Selection Using Dash

DocsPricing
  • 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import dash
from dash import dcc, html
from dash.dependencies import Input, Output
import pandas as pd

# Load the dataset
url = 'https://raw.githubusercontent.com/plotly/datasets/master/Dash-Course/makeup-shades/shades.csv'
df = pd.read_csv(url)

# Get unique brands for the dropdown
unique_brands = df['brand'].unique()

# Define the mapping of numbers to strings for the group column
group_mapping = {
    0: "Face", 
    1: "Eyes", 
    2: "Lips", 
    3: "Cheeks", 
    4: "Nails", 
    5: "Skincare", 
    6: "Tools", 
    7: "Other"
}

# Get unique sorted group values
unique_groups = sorted(df['group'].unique())

# External stylesheets (Bootstrap for general styling)
external_stylesheets = ['https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css']

# Create Dash app
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

# Custom CSS for styling
app.index_string = '''
<!DOCTYPE html>
<html>
    <head>
        {%metas%}
        <title>Girly Makeup Shades App</title>
        {%favicon%}
        {%css%}
        <style>
            body {
                background-color: #fce4ec;
                color: #880e4f;
                font-family: 'Arial, sans-serif';
            }
            .container {
                padding-top: 50px;
            }
            .dropdown, .radio {
                margin-bottom: 20px;
            }
            #output-div {
                margin-top: 30px;
                font-size: 18px;
                font-weight: bold;
                color: #ad1457;
            }
        </style>
    </head>
    <body>
        <div class="container">
            {%app_entry%}
        </div>
        <footer>
            {%config%}
            {%scripts%}
            {%renderer%}
        </footer>
    </body>
</html>
'''

app.layout = html.Div([
    # Dropdown for brands
    dcc.Dropdown(
        id='brand-dropdown',
        options=[{'label': brand, 'value': brand} for brand in unique_brands],
        value='Revlon',  # Initial value
        className='dropdown'
    ),
    # RadioItems for groups
    dcc.RadioItems(
        id='group-radioitems',
        options=[{'label': group_mapping[group], 'value': group} for group in unique_groups],
        value=0,  # Initial value
        className='radio'
    ),
    # Output div
    html.Div(id='output-div')
], className='container')

# Callback to update output based on selected brand and group
@app.callback(
    Output('output-div', 'children'),
    [Input('brand-dropdown', 'value'),
     Input('group-radioitems', 'value')]
)
def update_output(selected_brand, selected_group):
    return f'Selected brand: {selected_brand}, Selected group: {group_mapping[selected_group]}'

if __name__ == '__main__':
    app.run_server(debug=True)