You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mport pandas as pd
from dash import Dash, dcc, html, Input, Output
import plotly.express as px
Load the data
data = pd.read_excel('davp dashboard dataset.xlsx')
Create the Dash app
app = Dash(name)
Create a list of unique teams for dropdowns
teams = pd.unique(data[['Team1', 'Team2']].values.ravel('K')).tolist() # Get unique teams from both columns
Layout of the dashboard
app.layout = html.Div([
html.H1("T20 Cricket Data Analytics Dashboard"),
# Dropdown for Team1
dcc.Dropdown(
id='team1-dropdown',
options=[{'label': team, 'value': team} for team in teams],
placeholder="Select Team 1"
),
# Dropdown for Team2
dcc.Dropdown(
id='team2-dropdown',
options=[],
placeholder="Select Team 2"
),
# Div to hold both graphs
html.Div([
# Graph for Winning Team
dcc.Graph(id='winning-team-graph', style={'flex': '70%'}),
# Graph for Toss Decision
dcc.Graph(id='toss-decision-graph', style={'flex': '30%'})
], style={'display': 'flex', 'width': '100%'})
])
Callback to update Team2 dropdown based on Team1 selection
@app.callback(
Output('team2-dropdown', 'options'),
Input('team1-dropdown', 'value')
)
def set_team2_options(selected_team1):
if selected_team1 is None:
return []
# Filter data to get teams that are not the selected Team1
filtered_data = data[(data['Team1'] == selected_team1) | (data['Team2'] == selected_team1)]
team2_options = pd.unique(filtered_data[['Team1', 'Team2']].values.ravel('K'))
team2_options = [{'label': team, 'value': team} for team in team2_options if team != selected_team1]
return team2_options
Callback to update the Winning Team and Toss Decision graphs based on selections
@app.callback(
Output('winning-team-graph', 'figure'),
Output('toss-decision-graph', 'figure'),
Input('team1-dropdown', 'value'),
Input('team2-dropdown', 'value')
)
def update_graph(selected_team1, selected_team2):
# Initialize figures
winning_fig = px.bar(title='Select Teams to See Winning Team Counts') # Placeholder figure
toss_fig = px.pie(title='Select Teams to See Toss Decision Counts') # Placeholder figure
if selected_team1 and selected_team2:
filtered_data = data[
(data['Team1'] == selected_team1) & (data['Team2'] == selected_team2)
]
# Create a bar plot for Winning Team
if not filtered_data.empty:
win_counts = filtered_data['Winning_Team'].value_counts().reset_index()
win_counts.columns = ['Winning_Team', 'Count']
winning_fig = px.bar(win_counts, x='Winning_Team', y='Count', title='Winning Team Counts')
# Create a pie plot for Toss Decision
toss_counts = filtered_data['Toss_Decision'].value_counts().reset_index()
toss_counts.columns = ['Toss_Decision', 'Count']
toss_fig = px.pie(toss_counts, names='Toss_Decision', values='Count', title='Toss Decision Counts')
return winning_fig, toss_fig
Run the app
if name == 'main':
app.run_server(debug=True)
The text was updated successfully, but these errors were encountered:
mport pandas as pd
from dash import Dash, dcc, html, Input, Output
import plotly.express as px
Load the data
data = pd.read_excel('davp dashboard dataset.xlsx')
Create the Dash app
app = Dash(name)
Create a list of unique teams for dropdowns
teams = pd.unique(data[['Team1', 'Team2']].values.ravel('K')).tolist() # Get unique teams from both columns
Layout of the dashboard
app.layout = html.Div([
html.H1("T20 Cricket Data Analytics Dashboard"),
])
Callback to update Team2 dropdown based on Team1 selection
@app.callback(
Output('team2-dropdown', 'options'),
Input('team1-dropdown', 'value')
)
def set_team2_options(selected_team1):
if selected_team1 is None:
return []
Callback to update the Winning Team and Toss Decision graphs based on selections
@app.callback(
Output('winning-team-graph', 'figure'),
Output('toss-decision-graph', 'figure'),
Input('team1-dropdown', 'value'),
Input('team2-dropdown', 'value')
)
def update_graph(selected_team1, selected_team2):
# Initialize figures
winning_fig = px.bar(title='Select Teams to See Winning Team Counts') # Placeholder figure
toss_fig = px.pie(title='Select Teams to See Toss Decision Counts') # Placeholder figure
Run the app
if name == 'main':
app.run_server(debug=True)
The text was updated successfully, but these errors were encountered: