hi Adam i am subscribe in ur youtube channel
with help of ur viedo’s i was replicating to try making own dasboard layout
from dash import Dash, html, dcc, Output, Input, dash_table, callback
import dash_bootstrap_components as dbc
import plotly.express as px
import pandas as pd
import numpy as np
import json
app = Dash(__name__, external_stylesheets=[dbc.themes.LUMEN, dbc.icons.FONT_AWESOME])
server = app.server
# geojson
india_states = "https://gist.githubusercontent.com/jbrobst/56c13bbbf9d97d187fea01ca62ea5112/raw/e388c4cae20aa53cb5090210a42ebb9b765c0a36/india_states.geojson"
recipe = pd.read_excel(r'C:\Users\User\data_science/recipe.xlsx')
recipe['Total time(min)'] = recipe['preparation time(min)'] + recipe['cooking time(min)']
print(recipe.head(5))
print(recipe.columns)
app.layout = dbc.Container([
dbc.Row([
dbc.Col([
html.Span([
html.I(className="fa-solid fa-bowl-rice"),
" Top 10 Food recipe ",
html.I(className="fa-solid fa-bowl-rice")], className='h2')
], width=10)
], justify='center', className='my-2'),
dbc.Row([
dbc.Col([html.Label('diet', className='bg-secondary')], width=3),
dbc.Col([html.Label('Top 10 Food', className='bg-secondary')], width={"size": 4, "offset": 3}),
]),
dbc.Row([
dbc.Col([
dcc.Dropdown([diet for diet in sorted(recipe['type of diet'].unique())], multi=True, id='diet_dpdn'),
html.Label('course of meal', className='bg-secondary'),
dcc.Dropdown([meal for meal in sorted(recipe['course of meal'].unique())], multi=True,
id='course_of_meal_dpdn'),
html.Label('drop down', className='bg-secondary'),
dcc.Dropdown(options=[
{'label': 'topmost', 'value': '0-10'},
{'label': '2nd topmost', 'value': '11-21'},
{'label': '3rd topmost', 'value': '22-32'},
{'label': '4th topmost', 'value': '33-43'},
{'label': '5th topmost', 'value': '44-54'},
{'label': '6th topmost', 'value': '55-65'}
], multi=False, id='top_ten_dpdn')
], width=3),
dbc.Col([
dcc.Graph(id='bar', config={'displayModeBar': False})
], width=9)
]),
dbc.Row([
dbc.Col([dcc.Graph(id='line', config={'displayModeBar': False})], width=5),
dbc.Col([dcc.Graph(id='choro', config={'displayModeBar': False})], width={"size": 5, "offset": 2})
])
])
@callback(
Output('bar', 'figure'),
Output('line', 'figure'),
Output('choro', 'figure'),
Input('diet_dpdn', 'value'),
Input('course_of_meal_dpdn', 'value'),
Input('top_ten_dpdn', 'value')
)
def update_graph(diet_v, course_of_meal_v, top_ten_v):
dff = recipe.copy()
dff.columns = [column.replace(" ", "_") for column in dff.columns]
print(type(diet_v))
if any([diet_v, course_of_meal_v, top_ten_v]):
if diet_v is not None:
if len(diet_v) > 0:
dff = dff.query(f"type_of_diet in {diet_v}")
if course_of_meal_v is not None:
if len(course_of_meal_v) > 0:
dff = dff.query(f"course_of_meal in {course_of_meal_v}")
if top_ten_v is not None:
if len(top_ten_v) > 0:
dff = dff.iloc[int(top_ten_v.split('-')[0]):int(top_ten_v.split('-')[1])]
dff = dff.reset_index(drop='True').head(10)
dff = dff.drop_duplicates(subset='name_of_the_dish')
fig_bar = px.bar(data_frame=dff,
x="content_view", y="name_of_the_dish", orientation='h').update_layout(
margin=dict(l=10, r=10, t=10, b=10), yaxis=dict(autorange="reversed"))
# dff = dff.reset_index(drop='True').head(10)
names = [name.split()[0] for name in dff['name_of_the_dish']]
fig_line_second = px.line(data_frame=dff, x='name_of_the_dish',
y=['preparation_time(min)', 'cooking_time(min)', 'Total_time(min)'],
labels={'value': 'time(min)'}, text='value'
, markers=True).update_layout(
margin=dict(l=1, r=1, t=1, b=1),
legend={'x': 0, 'y': 1, 'bgcolor': 'rgba(0, 0, 0, 0)', 'title': None})
fig_line_second.update_xaxes(tickvals=np.arange(10), ticktext=names)
fig_line_second.update_traces(textfont_size=10, textposition="bottom right", cliponaxis=False)
fig_choropleth = px.choropleth(dff, locations='state', geojson=india_states, featureidkey='properties.ST_NM',
locationmode='geojson-id', color='content_view')
fig_choropleth.update_geos(fitbounds="locations", visible=False)
fig_choropleth.update_layout(margin=dict(l=1, r=1, t=1, b=1))
return fig_bar, fig_line_second, fig_choropleth
if not any([diet_v, course_of_meal_v]):
dff = dff.reset_index(drop='True').head(10)
fig_bar = px.bar(data_frame=dff,
x="content_view", y="name_of_the_dish", orientation='h').update_layout(
margin=dict(l=10, r=10, t=10, b=10), yaxis=dict(autorange="reversed"))
# dff = dff.reset_index(drop='True').head(10)
names = [name.split()[0] for name in dff['name_of_the_dish']]
fig_line_second = px.line(data_frame=dff, x='name_of_the_dish',
y=['preparation_time(min)', 'cooking_time(min)', 'Total_time(min)'],
labels={'value': 'time(min)'}, text='value'
, markers=True).update_layout(
margin=dict(l=1, r=1, t=1, b=1),
legend={'x': 0, 'y': 1, 'bgcolor': 'rgba(0, 0, 0, 0)', 'title': None})
fig_line_second.update_xaxes(tickvals=np.arange(10), ticktext=names)
fig_line_second.update_traces(textfont_size=10, textposition="bottom right", cliponaxis=False)
fig_choropleth = px.choropleth(dff, locations='state', geojson=india_states, featureidkey='properties.ST_NM',
locationmode='geojson-id', color='content_view')
fig_choropleth.update_geos(fitbounds="locations", visible=False)
fig_choropleth.update_layout(margin=dict(l=1, r=1, t=1, b=1))
return fig_bar, fig_line_second, fig_choropleth
if __name__ == '__main__':
app.run(debug=True)
[data]
(recipe.xlsx - Google Sheets)
jeo-jason file map i had taken from github