daniel-dobos commited on
Commit
65e8b85
·
1 Parent(s): e81083a

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -0
  2. app.ipynb +238 -0
  3. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . .
10
+
11
+ CMD ["mnn", "serve", "/code/app.ipynb", "--address", "0.0.0.0", "--port", "7860", "--allow-websocket-origin", "*"]
app.ipynb ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import manganite\n",
10
+ "%load_ext manganite"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "markdown",
15
+ "metadata": {},
16
+ "source": [
17
+ "# CO2 Emission Dashboard\n",
18
+ "\n",
19
+ "## Overview\n",
20
+ "This CO2 emission dashboard provides valuable insights into global carbon dioxide emissions. It features three distinct plots that help users explore emissions data by continents and countries. Additionally, it allows users to filter emissions by their source type. \n",
21
+ "\n",
22
+ "## Plots\n",
23
+ "\n",
24
+ "### Plot 1: CO2 Emission Over Time (Continents)\n",
25
+ "- **Description:** This line plot illustrates the trends in CO2 emissions over time for different continents.\n",
26
+ "\n",
27
+ "### Plot 2: CO2 Emission vs. GDP per Capita (Countries)\n",
28
+ "- **Description:** This scatter plot allows users to explore the relationship between CO2 emissions and GDP per capita for individual countries.\n",
29
+ "\n",
30
+ "### Plot 3: CO2 Emission by Continent (Filtered by Source)\n",
31
+ "- **Description:** This bar chart provides a breakdown of CO2 emissions for each continent, allowing users to filter emissions by source type.\n",
32
+ "\n",
33
+ "## Technologies Used\n",
34
+ "- Programming Language: Python\n",
35
+ "- Data Visualization Library: Plotly\n",
36
+ "\n",
37
+ "## Data Source\n",
38
+ "The data used in this dashboard is sourced from [Our World in Data](https://ourworldindata.org).\n",
39
+ "\n",
40
+ "## GitHub Repository\n",
41
+ "This project is based on the following GitHub repository: [GitHub Repo](https://github.com/thu-vu92/python-dashboard-panel/tree/main)\n",
42
+ "\n",
43
+ "Explore and analyze global CO2 emissions with this interactive dashboard. Select plots and filters to gain insights into the environmental impact and economic factors related to emissions worldwide.\n"
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": null,
49
+ "metadata": {},
50
+ "outputs": [],
51
+ "source": [
52
+ "# Import the Python packages\n",
53
+ "import pandas as pd\n",
54
+ "import numpy as np\n",
55
+ "import plotly.express as px\n"
56
+ ]
57
+ },
58
+ {
59
+ "cell_type": "code",
60
+ "execution_count": 31,
61
+ "metadata": {},
62
+ "outputs": [],
63
+ "source": [
64
+ "try:\n",
65
+ " df = pd.read_csv('owid-co2-data.csv')\n",
66
+ "except:\n",
67
+ " df = pd.read_csv('https://raw.githubusercontent.com/owid/co2-data/master/owid-co2-data.csv')"
68
+ ]
69
+ },
70
+ {
71
+ "cell_type": "code",
72
+ "execution_count": null,
73
+ "metadata": {},
74
+ "outputs": [],
75
+ "source": [
76
+ "# Fill NAs with 0s and create GDP per capita column\n",
77
+ "df = df.fillna(0)\n",
78
+ "df['gdp_per_capita'] = np.where(df['population']!= 0, df['gdp']/ df['population'], 0)"
79
+ ]
80
+ },
81
+ {
82
+ "cell_type": "code",
83
+ "execution_count": null,
84
+ "metadata": {},
85
+ "outputs": [],
86
+ "source": [
87
+ "#Add slider"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": null,
93
+ "metadata": {},
94
+ "outputs": [],
95
+ "source": [
96
+ "%%mnn widget --type slider 1900:2015:5 --tab \"Emission\" --header \"Year\" --var year_slider\n",
97
+ "year_slider = 2010"
98
+ ]
99
+ },
100
+ {
101
+ "cell_type": "code",
102
+ "execution_count": null,
103
+ "metadata": {},
104
+ "outputs": [],
105
+ "source": [
106
+ "# add selector\n",
107
+ "options=['co2', 'co2_per_capita']"
108
+ ]
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "execution_count": null,
113
+ "metadata": {},
114
+ "outputs": [],
115
+ "source": [
116
+ "%%mnn widget --type radio options --tab \"Emission\" --header \"Y - axis\" --var yaxis_co2\n",
117
+ "yaxis_co2 = options[0]"
118
+ ]
119
+ },
120
+ {
121
+ "cell_type": "code",
122
+ "execution_count": null,
123
+ "metadata": {},
124
+ "outputs": [],
125
+ "source": [
126
+ "# Continent Selector\n",
127
+ "continents = ['World', 'Asia', 'Oceania', 'Europe', 'Africa', 'North America', 'South America', 'Antarctica']"
128
+ ]
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ "execution_count": null,
133
+ "metadata": {},
134
+ "outputs": [],
135
+ "source": [
136
+ "# %%mnn widget --type select continents --tab \"Emission\" --header \"Select Continent\" --var continent --position 1 1 4\n",
137
+ "# continent = continents[0]"
138
+ ]
139
+ },
140
+ {
141
+ "cell_type": "code",
142
+ "execution_count": null,
143
+ "metadata": {},
144
+ "outputs": [],
145
+ "source": [
146
+ "%%mnn widget --type plot --var fig_0 --tab \"Emission\" --header \"CO2 Emission by continent\"\n",
147
+ "# Adding chart 0\n",
148
+ "df_0 = df[(df['year'] <= year_slider) & (df['year'] >= 1890) & (df['country'].isin(continents))]\n",
149
+ "fig_0 = px.line(df_0, x='year', y= yaxis_co2, color='country')\n"
150
+ ]
151
+ },
152
+ {
153
+ "cell_type": "code",
154
+ "execution_count": null,
155
+ "metadata": {},
156
+ "outputs": [],
157
+ "source": [
158
+ "# fig_0.show()"
159
+ ]
160
+ },
161
+ {
162
+ "cell_type": "code",
163
+ "execution_count": null,
164
+ "metadata": {},
165
+ "outputs": [],
166
+ "source": [
167
+ "%%mnn widget --type plot --var fig_1 --tab \"Emission\" --header \"CO2 vs GDP\"\n",
168
+ "\n",
169
+ "df_1 = df[(df['year'] == year_slider) & (-df['country'].isin(continents)) & (df['gdp_per_capita'] != 0)& (df['co2_per_capita'] != 0)& (df['co2'] != 0)]\n",
170
+ "fig_1 = px.scatter(df_1, x=\"gdp_per_capita\", y= yaxis_co2 , hover_data = \"country\")\n",
171
+ "# fig_1.update_traces(textposition=\"top right\")"
172
+ ]
173
+ },
174
+ {
175
+ "cell_type": "code",
176
+ "execution_count": null,
177
+ "metadata": {},
178
+ "outputs": [],
179
+ "source": [
180
+ "# fig_1.show()"
181
+ ]
182
+ },
183
+ {
184
+ "cell_type": "code",
185
+ "execution_count": null,
186
+ "metadata": {},
187
+ "outputs": [],
188
+ "source": [
189
+ "emission_types=['coal_co2', 'oil_co2', 'gas_co2']"
190
+ ]
191
+ },
192
+ {
193
+ "cell_type": "code",
194
+ "execution_count": null,
195
+ "metadata": {},
196
+ "outputs": [],
197
+ "source": [
198
+ "%%mnn widget --type select emission_types --tab \"Emission\" --header \"Select Emission Source\" --var source --position -1 0 1\n",
199
+ "source = emission_types[0]"
200
+ ]
201
+ },
202
+ {
203
+ "cell_type": "code",
204
+ "execution_count": null,
205
+ "metadata": {},
206
+ "outputs": [],
207
+ "source": [
208
+ "%%mnn widget --type plot --var fig_2 --tab \"Emission\" --header \"CO2 source by continent\" --position -1 1 4\n",
209
+ "\n",
210
+ "df_2 = df[(df['year'] == year_slider) & (df['country'].isin(continents))]\n",
211
+ "\n",
212
+ "fig_2 = px.bar(df_2, x='country' , y = source)"
213
+ ]
214
+ }
215
+ ],
216
+ "metadata": {
217
+ "kernelspec": {
218
+ "display_name": "manganite-env",
219
+ "language": "python",
220
+ "name": "python3"
221
+ },
222
+ "language_info": {
223
+ "codemirror_mode": {
224
+ "name": "ipython",
225
+ "version": 3
226
+ },
227
+ "file_extension": ".py",
228
+ "mimetype": "text/x-python",
229
+ "name": "python",
230
+ "nbconvert_exporter": "python",
231
+ "pygments_lexer": "ipython3",
232
+ "version": "3.11.4"
233
+ },
234
+ "orig_nbformat": 4
235
+ },
236
+ "nbformat": 4,
237
+ "nbformat_minor": 2
238
+ }
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ jupyter
2
+ pandas
3
+ plotly
4
+ https://github.com/daniel-dobos-unilu/codespaces-manganite/raw/main/packages/manganite-0.0.3.tar.gz