728x90
반응형
SMALL
라이브러리 설치
!pip install dash jupyter-dash dash-bootstrap-components
데이터 로드
import pandas as pd
import plotly.express as px
from dash import Dash, dcc, html, Input, Output
import dash_bootstrap_components as dbc
df = pd.read_csv('https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv')
num_features = df.select_dtypes(include='number').columns
df.head()
main
# dash app 초기화
app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
app.layout = dbc.Container([
dbc.Row([
dbc.Col([
html.H1("Titanic Dashboard"),
dcc.Dropdown(
id='survived-dropdown',
options=[
{'label': 'Survived', 'value': 1},
{'label': 'Not Survived', 'value': 0}
],
value=1,
clearable=False,
style={"width": "50%"}
),
dcc.Dropdown(
id='feature-dropdown',
options=[{'label': feature, 'value': feature} for feature in num_features],
value='Fare',
clearable=False,
style={"width": "50%"}
),
dcc.Graph(id='scatter-plot')
], width=12)
])
], fluid=True)
@app.callback(
Output('scatter-plot', 'figure'),
[Input('survived-dropdown', 'value'), Input('feature-dropdown', 'value')]
)
def update_figure(survived_value, feature_value):
filtered_df = df[df['Survived'] == survived_value]
fig = px.scatter(filtered_df, x='Age', y=feature_value, color='Pclass', title=f'Survived = {survived_value}, Feature = {feature_value}')
return fig
if __name__ == '__main__':
app.run_server(debug=True)
728x90
반응형
LIST
'Programming > Python' 카테고리의 다른 글
[Python] pyenv 버전 관리 (0) | 2024.11.06 |
---|---|
[Python] pyenv (0) | 2024.05.13 |
[Python] GUI 실행 파일 만들기 (0) | 2023.11.10 |
[Python] NotOpenSSLWarning: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020 (0) | 2023.07.21 |
[Python] 에러 핸들링 (0) | 2023.06.20 |