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)