forked from plotly/odsc-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
5_style_css.py
49 lines (39 loc) · 1.49 KB
/
5_style_css.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
# Import packages
from dash import Dash, html, dash_table, dcc, callback, Output, Input
import pandas as pd
import plotly.express as px
# Incorporate data
df = px.data.gapminder()
# Initialize the app - incorporate css
external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"]
app = Dash(__name__, external_stylesheets=external_stylesheets)
# App layout
app.layout = html.Div([
html.Div(className="row", children="My First App with Data, Graph, and Controls",
style={"textAlign": "center", "color": "blue", "fontSize": 30}),
html.Div(className="row", children=[
dcc.RadioItems(options=["pop", "lifeExp", "gdpPercap"],
value="lifeExp",
inline=True,
id="metric-controls")
]),
html.Div(className="row", children=[
html.Div(className="six columns", children=[
dash_table.DataTable(data=df.to_dict("records"), page_size=10, style_table={"overflowX": "auto"})
]),
html.Div(className="six columns", children=[
dcc.Graph(figure={}, id="my-graph")
])
])
])
# Add controls to build the interaction
@callback(
Output(component_id="my-graph", component_property="figure"),
Input(component_id="metric-controls", component_property="value")
)
def update_graph(col_chosen):
fig = px.histogram(df, x="continent", y=col_chosen, histfunc="avg")
return fig
# Run the app
if __name__ == "__main__":
app.run_server(debug=True)