-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
77 lines (72 loc) · 1.91 KB
/
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
from dash import Dash, html, dash_table, dcc
import plotly.express as px
import pandas_dash as pdd
# App
print(pdd.__version__)
app = Dash(__name__, title="Pandas-Dash")
server = app.server
gdp = px.data.gapminder()
country_options = gdp.dash.to_options(label="country", title="continent")
flat_data = gdp.head(50)
flat_data, flat_columns = flat_data.dash.to_dash_table()
gdp["country"] = (
"["
+ gdp["country"]
+ "](https://en.wikipedia.org/wiki/"
+ gdp["country"].str.replace(" ", "_")
+ ")"
)
gdp = gdp.sort_values(["continent", "country", "year"])
gdp = (
gdp.pivot(
index=["continent", "country"],
columns="year",
values=["gdpPercap", "pop"],
)
.round(2)
.reset_index()
)
styling, _ = pdd.heatmap(gdp, n_bins=9)
print(styling)
gdp, gdp_columns = gdp.dash.to_dash_table(
column_properties={"country": {"presentation": "markdown"}}
)
tips = px.data.tips()
tips = (
tips.pivot_table(
index=["day", "time", "size"],
columns=["sex", "smoker"],
values=["tip", "total_bill"],
)
.reset_index()
.round(2)
)
tips, tips_columns = tips.dash.to_dash_table()
app.layout = html.Div(
children=[
dcc.Dropdown(options=country_options, value="China"),
dash_table.DataTable(
data=flat_data,
columns=flat_columns,
),
dash_table.DataTable(
data=gdp,
columns=gdp_columns,
sort_action="native",
sort_mode="multi",
filter_action="native",
style_data_conditional=styling,
merge_duplicate_headers=True,
),
dash_table.DataTable(
data=tips,
columns=tips_columns,
sort_action="native",
sort_mode="multi",
filter_action="native",
merge_duplicate_headers=True,
),
]
)
if __name__ == "__main__":
app.run_server(debug=True)