Using Dash with Python to create interactive Dashboard Visualization

[1344 views]




What is DASH?

DASH is a newly introduced library in the rich portfolio of components ready to use with Python code. It uses the FLASK infrastructure as a base and has capability to map HTML tags to python code and produce interactive dashboards.

With the commencement of time, python is replacing and hovering over the become the first preferences for all the different flavors of software development. Interactive web portals was a field where python was lacking a bit and PHP was the first preference of majority of developers. But in the recent advancements, some open source libraries has been released which has the functionality of building web pages using python as a base development environment. One of such library is DASH.

Here, are the very basic commands using which one can prepare an interactive dashboard which will be hosted through a web page.

For this we need to first install DASH using-

pip install dash

then using the following base code:

from dash import Dash from dash import dcc from dash import html data = pd.read_csv("emissions.csv") data=data.groupby(['Vehicle class']).agg({'Co2': 'sum'}).reset_index() app = Dash(__name__) app.layout = html.Div( children=[ html.H1(children="Emissions"), html.H3("Sprint 1 - Annual Emissions, on a scale of 100"), dcc.Graph( figure=fig, ), html.H3("Sprint 2 - Emission based on Vehicle Type "), dcc.Graph( figure={ "data": [ { "x": data["Vehicle class"], "y": data["Co2"], "type": "lines", }, ], "layout": {"title" : "Emissions"}, }, ), ] ) if __name__ == "__main__": app.run_server(debug=True)

emissions.csv file:

Vehicle class Time of day Mon Tue Co2 Nox
car 1 11.4 9.8 19826.18 60.99766
car 2 6.1 5.4 10754.77 33.08835
car 3 4.5 4.1 8042.694 24.74433
car 4 5.4 4.6 9351.97 28.77248
car 5 11 8.9 18610.42 57.25724
car 6 35 31.4 62097.08 191.0493
car 7 88.8 87.2 164594.7 506.3956
car 8 174.9 176.7 328815.3 1011.64
car 9 198.5 202.7 375201 1154.352
car 10 140.8 144.7 266998.7 821.4543
car 11 133.9 130.1 246892 759.5935
car 12 139.8 132.7 254841.2 784.0501
car 13 143.3 138.2 263258 809.9453
car 14 143.3 139.7 264660.7 814.2612
car 15 151.7 149.8 281961.9 867.4903
car 16 172.9 175.5 325822.6 1002.433
car 17 202 208.1 383524.3 1179.959
car 18 217.4 224.5 413263.5 1271.456
car 19 161.1 171.3 310859.5 956.3972
car 20 105.6 113.7 205088.7 630.9805
car 21 72.3 76.8 139437.9 428.9977
car 22 53.3 58.2 104274.5 320.8132
car 23 35.6 41.1 71729.61 220.6849
car 24 18.7 21.2 37314.36 114.8022
light vehicle 1 10.8 10 24282.13 74.70694
light vehicle 2 7.1 6.7 16110.26 49.56518
light vehicle 3 6 6 14008.92 43.10016
light vehicle 4 7.9 7.4 17861.37 54.9527
light vehicle 5 16.7 13.9 35722.75 109.9054
light vehicle 6 45.4 39.7 99346.6 305.652
light vehicle 7 115.4 114.4 268270.8 825.3681
light vehicle 8 204.6 208.5 482257.1 1483.723
light vehicle 9 214 220 506656 1558.789
light vehicle 10 172.7 176.4 407542.9 1253.855
light vehicle 11 155.6 155.6 363298 1117.731
light vehicle 12 156.7 156.2 365282.6 1123.837
light vehicle 13 157.1 157.5 367267.2 1129.943
light vehicle 14 157.6 158.8 369368.5 1136.408
light vehicle 15 166.1 171.2 393767.4 1211.474
light vehicle 16 192.4 199.8 457858.2 1408.657
light vehicle 17 212.6 221.3 506539.2 1558.43
light vehicle 18 194 204.4 465096.2 1430.925
                 





Comments





Search
Get Answers to your Programming Questions


Recommended Deals ends in








Test Your Skills:

Search Tags