-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
46 lines (39 loc) · 1.35 KB
/
app.py
File metadata and controls
46 lines (39 loc) · 1.35 KB
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
from flask import Flask, render_template, request
import plotly.express as px
import pandas as pd
import numpy as np
import json
import plotly
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def index():
chart_type = request.form.get("chart_type", "box")
# Generate coffee export data
df = pd.read_csv("coffee_exports.csv")
df = df.rename(columns={
"Country": "Category",
"Export_Value_USD": "Value",
"Region": "Group"
})
# Select chart type
if chart_type == "bar":
fig = px.bar(df, x="Category", y="Value", color="Group", title="Bar Chart")
elif chart_type == "scatter":
fig = px.scatter(df, x="Category", y="Value", color="Group", title="Scatter Plot")
else:
fig = px.box(df, x="Category", y="Value", color="Group", title="Box Plot")
# Dark layout
fig.update_layout(
plot_bgcolor='#1a1c23',
paper_bgcolor='#1a1c23',
font_color='#ffffff',
autosize=True,
margin=dict(t=50, l=50, r=50, b=50),
height=600
)
fig.update_xaxes(showgrid=False, color='#cccccc')
fig.update_yaxes(showgrid=False, color='#cccccc')
graphJSON = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
return render_template("index.html", graphJSON=graphJSON, chart_type=chart_type)
if __name__ == "__main__":
app.run(debug=True)