forked from Coding-with-Adam/practice-pull-request
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo-app.py
88 lines (74 loc) · 3.22 KB
/
demo-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
import dash # pip install dash
import dash_bootstrap_components as dbc # pip install dash-bootstrap-components
import dash_html_components as html
import dash_core_components as dcc
import plotly.express as px
from dash.dependencies import Input, Output
# This comment should be deleted
df = px.data.gapminder()
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.CYBORG])
card_main = dbc.Card(
[
dbc.CardImg(src="/assets/ball_of_sun.jpg", top=True, bottom=False,
title="Image by Kevin Dinkel", alt='Learn Dash Bootstrap Card Component'),
dbc.CardBody(
[
html.H4("Learn Dash with Charming Data", className="card-title"),
html.H6("Lesson 1:", className="card-subtitle"),
html.P(
"Choose the year you would like to see on the bubble chart.",
className="card-text",
),
dcc.Dropdown(id='user_choice', options=[{'label': yr, "value": yr} for yr in df.year.unique()],
value=2007, clearable=False, style={"color": "#000000"}),
# dbc.Button("Press me", color="primary"),
# dbc.CardLink("GirlsWhoCode", href="https://girlswhocode.com/", target="_blank"),
]
),
],
color="darkblue", # https://bootswatch.com/default/ for more card colors
inverse=True, # change color of text (black or white)
outline=False, # True = remove the block colors from the background and header
)
card_question = dbc.Card(
[
dbc.CardBody([
html.H4("Question 1", className="card-title"),
html.P("What was India's life expectancy in 1952?", className="card-text"),
dbc.ListGroup(
[
dbc.ListGroupItem("A. 55 years"),
dbc.ListGroupItem("B. 37 years"),
dbc.ListGroupItem("C. 49 years"),
], flush=True)
]),
], color="warning",
)
card_graph = dbc.Card(
dcc.Graph(id='my_bar', figure={}), body=True, color="secondary",
)
app.layout = html.Div([
dbc.Row([dbc.Col(card_main, width=3),
dbc.Col(card_question, width=3),
dbc.Col(card_graph, width=5)], justify="around"), # justify="start", "center", "end", "between", "around"
# dbc.CardGroup([card_main, card_question, card_graph]) # attaches cards with equal width and height columns
# dbc.CardDeck([card_main, card_question, card_graph]) # same as CardGroup but with gutter in between cards
# dbc.CardColumns([ # Cards organised into Masonry-like columns
# card_main,
# card_question,
# card_graph,
# card_question,
# card_question,
# ])
])
@app.callback(
Output("my_bar", "figure"),
[Input("user_choice", "value")]
)
def update_graph(value):
fig = px.scatter(df.query("year=={}".format(str(value))), x="gdpPercap", y="lifeExp",
size="pop", color="continent", title=str(value),
hover_name="country", log_x=True, size_max=60).update_layout(showlegend=True, title_x=0.5)
return fig
if __name__ == "__main__":
app.run_server(debug=True)