from
flask
import
Flask, render_template
import
pandas as pd
import
json
import
plotly
import
plotly.express as px
app
=
Flask(__name__)
@app
.route(
'/'
)
def
bar_with_plotly():
students
=
[[
'Akash'
,
34
,
'Sydney'
,
'Australia'
],
[
'Rithika'
,
30
,
'Coimbatore'
,
'India'
],
[
'Priya'
,
31
,
'Coimbatore'
,
'India'
],
[
'Sandy'
,
32
,
'Tokyo'
,
'Japan'
],
[
'Praneeth'
,
16
,
'New York'
,
'US'
],
[
'Praveen'
,
17
,
'Toronto'
,
'Canada'
]]
df
=
pd.DataFrame(students,
columns
=
[
'Name'
,
'Age'
,
'City'
,
'Country'
],
index
=
[
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
])
fig
=
px.bar(df, x
=
'Name'
, y
=
'Age'
, color
=
'City'
, barmode
=
'group'
)
graphJSON
=
json.dumps(fig,
cls
=
plotly.utils.PlotlyJSONEncoder)
return
render_template(
'bar.html'
, graphJSON
=
graphJSON)
if
__name__
=
=
'__main__'
:
app.run(debug
=
True
)