-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
70 lines (49 loc) · 1.51 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
from flask import Flask, render_template, jsonify
from vega_datasets import data
import altair as alt
import pandas as pd
alt.data_transformers.enable("default", max_rows=None)
cars = data.cars()
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/vega-example1")
def vega_example1():
chart = (
alt.Chart(cars)
.mark_point()
.encode(x="Horsepower", y="Miles_per_Gallon", color="Origin", shape="Origin")
)
return jsonify(chart.to_dict())
@app.route("/vega-example2")
def vega_example2():
chart = (
alt.Chart(cars)
.mark_point()
.encode(y="Horsepower:Q", color="Origin:N")
.interactive()
)
chart = chart.encode(x="Acceleration:Q") | chart.encode(x="Displacement:Q")
return jsonify(chart.to_dict())
@app.route("/vega-example3")
def vega_example3():
brush = alt.selection_interval()
chart = (
alt.Chart(cars)
.mark_point()
.encode(
alt.X(alt.repeat("column"), type="quantitative"),
alt.Y(alt.repeat("row"), type="quantitative"),
color=alt.condition(brush, "Origin:N", alt.value("gray")),
)
.add_selection(brush)
.properties(width=250, height=250)
.repeat(
row=["Horsepower", "Miles_per_Gallon"],
column=["Acceleration", "Displacement"],
)
)
return jsonify(chart.to_dict())
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000, debug=True)