Spaces:
Sleeping
Sleeping
Update dashboard.py
Browse files- dashboard.py +422 -404
dashboard.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
|
|
|
2 |
import warnings
|
3 |
warnings.filterwarnings("ignore")
|
4 |
import io
|
@@ -31,416 +32,433 @@ from bokeh.resources import INLINE
|
|
31 |
from holoviews.operation.timeseries import rolling, rolling_outlier_std
|
32 |
hv.extension('bokeh')
|
33 |
|
34 |
-
## LOAD DATASETS
|
35 |
|
36 |
-
#
|
37 |
-
|
38 |
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
macro_topics = ["Energy-Efficient Building Design for Thermal Comfort and Sustainability","Indoor Air Quality and Energy Efficiency in Low-Energy Houses","Urban Planning and Development in China\'s Cities", "Design Thinking and Sustainable Product Development", "Smart Cities and Urban Computing", "Urban Resilience and Water Management","Renewable Energy Systems: Solar PV & Building Applications","Exploring the Intersection of Traditional Heritage and Modern Steel Architecture in Historical Buildings","Green Building Assessment and Design","Landscape Design, Planning, and Research: Integrating Cultural, Ecological, and Rural Perspectives", "Noise and Acoustic Design in Urban Development","Sustainable Building Materials: Wood & 3D Printing Innovations","BIM in AEC: Trends, Challenges, and Opportunities","Urban Food Systems: Community Development and Social Sustainability in Cities","Innovative Bridge Design and Construction: Trends and Case Studies", "Cavity Flow and Heat Transfer"]
|
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 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
k, v = row
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
81 |
k, v = row
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
for
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
#
|
293 |
-
|
294 |
-
|
295 |
-
#
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
#
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
384 |
)
|
385 |
-
|
386 |
-
def CreatePage4():
|
387 |
-
return pn.Column(
|
388 |
-
pn.pane.Markdown("## Top Key Entities "),
|
389 |
-
pn.Row(pn.Column(radio_buttons_regions, radio_buttons_types), dmap2),
|
390 |
-
align="center", )
|
391 |
-
|
392 |
-
def CreatePage5():
|
393 |
-
return pn.Column(
|
394 |
-
pn.pane.Markdown("## Entity Chord Diagrams "),
|
395 |
-
pn.Row(region_radio_button, pn.bind(filter_region, region_radio_button)),
|
396 |
-
align="center", )
|
397 |
-
|
398 |
-
|
399 |
-
def CreatePage6():
|
400 |
-
html = """<iframe src="https://app.vosviewer.com/?json=https%3A%2F%2Fdrive.google.com%2Fuc%3Fid%3D16q1oLQyEeMosAgeD9UkC9hSrpzAYX_-n" width="800" height="800"></iframe>"""
|
401 |
-
|
402 |
-
html_pane = pn.pane.HTML(html)
|
403 |
-
#url = 'https://app.vosviewer.com/?json=https%3A%2F%2Fdrive.google.com%2Fuc%3Fid%3D16q1oLQyEeMosAgeD9UkC9hSrpzAYX_-n'
|
404 |
-
return html_pane
|
405 |
-
#panel.show()
|
406 |
-
#return pn.Column(
|
407 |
-
# pn.pane.Markdown("## VOSViewer Network "),
|
408 |
-
# pn.Row(panel)
|
409 |
-
# )
|
410 |
-
|
411 |
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
#"Page4": CreatePage4(),
|
417 |
-
#"Page5": CreatePage5(),
|
418 |
-
"Page6": CreatePage6()
|
419 |
-
}
|
420 |
-
|
421 |
-
#################### SIDEBAR LAYOUT ##########################
|
422 |
-
sidebar = pn.Column(pn.pane.Markdown("## Pages"), button1,button2,#button3,
|
423 |
-
#button4,
|
424 |
-
#button5,
|
425 |
-
#button6,
|
426 |
-
styles={"width": "100%", "padding": "15px"})
|
427 |
-
|
428 |
-
#################### MAIN AREA LAYOUT ##########################
|
429 |
-
main_area = pn.Column(mapping["Page1"], styles={"width":"100%"})
|
430 |
-
|
431 |
-
###################### APP LAYOUT ##############################
|
432 |
-
template = pn.template.BootstrapTemplate(
|
433 |
-
title=" AECO Tech Dashboard",
|
434 |
-
sidebar=[sidebar],
|
435 |
-
main=[main_area],
|
436 |
-
header_background="black",
|
437 |
-
#site="Charting the Landscape of AECO Research",
|
438 |
-
theme=pn.template.DarkTheme,
|
439 |
-
sidebar_width=250, ## Default is 330
|
440 |
-
busy_indicator=pn.indicators.BooleanStatus(value=True),
|
441 |
-
)
|
442 |
-
|
443 |
-
### DEPLOY APP
|
444 |
|
445 |
-
|
446 |
-
|
|
|
1 |
|
2 |
+
from flask import Flask, send_from_directory
|
3 |
import warnings
|
4 |
warnings.filterwarnings("ignore")
|
5 |
import io
|
|
|
32 |
from holoviews.operation.timeseries import rolling, rolling_outlier_std
|
33 |
hv.extension('bokeh')
|
34 |
|
|
|
35 |
|
36 |
+
# Create a Flask app
|
37 |
+
app = Flask(__name__)
|
38 |
|
39 |
+
# Serve the HTML file from the 'static' directory
|
40 |
+
@app.route('/static/<path:path>')
|
41 |
+
def serve_static(path):
|
42 |
+
return send_from_directory('static', path)
|
43 |
|
|
|
44 |
|
45 |
+
# Panel-based dashboard
|
46 |
+
@app.route('/')
|
47 |
+
def dashboard():
|
48 |
+
|
49 |
+
## LOAD DATASETS
|
50 |
+
|
51 |
+
#static_folder = '/static'
|
52 |
+
dna_folder = './data'
|
53 |
+
|
54 |
+
|
55 |
+
macro_topics = ["Energy-Efficient Building Design for Thermal Comfort and Sustainability","Indoor Air Quality and Energy Efficiency in Low-Energy Houses","Urban Planning and Development in China\'s Cities", "Design Thinking and Sustainable Product Development", "Smart Cities and Urban Computing", "Urban Resilience and Water Management","Renewable Energy Systems: Solar PV & Building Applications","Exploring the Intersection of Traditional Heritage and Modern Steel Architecture in Historical Buildings","Green Building Assessment and Design","Landscape Design, Planning, and Research: Integrating Cultural, Ecological, and Rural Perspectives", "Noise and Acoustic Design in Urban Development","Sustainable Building Materials: Wood & 3D Printing Innovations","BIM in AEC: Trends, Challenges, and Opportunities","Urban Food Systems: Community Development and Social Sustainability in Cities","Innovative Bridge Design and Construction: Trends and Case Studies", "Cavity Flow and Heat Transfer"]
|
56 |
+
|
57 |
+
|
58 |
+
|
59 |
+
## AECO topic over time html file:
|
60 |
+
AECO_topics_over_time_file_path = '/static/optimized_merged_AECO_topics_over_time_2D.html'
|
61 |
+
|
62 |
+
#### full data unfiltered:
|
63 |
+
|
64 |
+
dna_articles_unfiltered_eu_time_indexed_resampled = pd.read_csv(os.path.join(dna_folder, 'dna_articles_unfiltered_eu_time_indexed_resampled.tsv'),sep='\t',header=0)
|
65 |
+
dna_articles_unfiltered_us_time_indexed_resampled = pd.read_csv(os.path.join(dna_folder, 'dna_articles_unfiltered_us_time_indexed_resampled.tsv'),sep='\t',header=0)
|
66 |
+
dna_articles_unfiltered_eu_us_time_indexed_resampled = pd.read_csv(os.path.join(dna_folder, 'dna_articles_unfiltered_eu_us_time_indexed_resampled.tsv'),sep='\t',header=0)
|
67 |
+
|
68 |
+
#### classifier filtered articles:
|
69 |
+
|
70 |
+
dh_ration_df_eu = pd.read_csv(os.path.join(dna_folder, 'dh_ration_df_eu.tsv'),sep='\t',header=0)
|
71 |
+
dh_ration_df_us = pd.read_csv(os.path.join(dna_folder, 'dh_ration_df_us.tsv'),sep='\t',header=0)
|
72 |
+
dh_ration_df_eu_us = pd.read_csv(os.path.join(dna_folder, 'dh_ration_df_eu_us.tsv'),sep='\t',header=0)
|
73 |
+
|
74 |
+
regions = ['eu', 'us', 'eu_us']
|
75 |
+
|
76 |
+
sorted_ent_type_freq_map_eu=dict()
|
77 |
+
sorted_ent_type_freq_map_us=dict()
|
78 |
+
sorted_ent_type_freq_map_eu_us=dict()
|
79 |
+
|
80 |
+
def read_top_ent_types():
|
81 |
+
reader = csv.reader(open(os.path.join(dna_folder, 'sorted_ent_type_freq_map_eu.tsv'), 'r'))
|
82 |
+
for i,row in enumerate(reader):
|
83 |
+
if i < 20:
|
84 |
+
k, v = row
|
85 |
+
sorted_ent_type_freq_map_eu[k] = int(v)
|
86 |
+
del sorted_ent_type_freq_map_eu['Entity']
|
87 |
+
reader = csv.reader(open(os.path.join(dna_folder, 'sorted_ent_type_freq_map_us.tsv'), 'r'))
|
88 |
+
for i, row in enumerate(reader):
|
89 |
+
if i < 20:
|
90 |
+
k, v = row
|
91 |
+
sorted_ent_type_freq_map_us[k] = int(v)
|
92 |
+
del sorted_ent_type_freq_map_us['Entity']
|
93 |
+
reader = csv.reader(open(os.path.join(dna_folder, 'sorted_ent_type_freq_map_eu_us.tsv'), 'r'))
|
94 |
+
for i, row in enumerate(reader):
|
95 |
+
if i < 20:
|
96 |
+
k, v = row
|
97 |
+
sorted_ent_type_freq_map_eu_us[k] = int(v)
|
98 |
+
del sorted_ent_type_freq_map_eu_us['Entity']
|
99 |
+
|
100 |
+
read_top_ent_types()
|
101 |
+
|
102 |
+
top_type_filtered_eu = ['DBpedia:Country', 'DBpedia:Organisation', 'DBpedia:Company', 'DBpedia:Person', 'DBpedia:Disease', 'DBpedia:ChemicalSubstance', 'DBpedia:Drug', 'DBpedia:GovernmentAgency', 'DBpedia:City', 'DBpedia:MonoclonalAntibody']
|
103 |
+
top_type_filtered_us = ['DBpedia:Organisation', 'DBpedia:Company', 'DBpedia:Disease', 'DBpedia:ChemicalSubstance', 'DBpedia:Person', 'DBpedia:Drug', 'DBpedia:Country', 'DBpedia:Region', 'DBpedia:MonoclonalAntibody', 'DBpedia:City', 'DBpedia:Biomolecule']
|
104 |
+
top_type_filtered_eu_us = ['DBpedia:Organisation', 'DBpedia:Company', 'DBpedia:ChemicalSubstance', 'DBpedia:Drug', 'DBpedia:Country', 'DBpedia:Person', 'DBpedia:Disease', 'DBpedia:MonoclonalAntibody', 'DBpedia:GovernmentAgency', 'DBpedia:Biomolecule', 'DBpedia:Gene']
|
105 |
+
|
106 |
+
dna_healthtech_articles_eu_time_indexed_resampled=pd.read_csv(os.path.join(dna_folder, 'dna_healthtech_articles_eu_time_indexed_resampled.tsv'),sep='\t',header=0)
|
107 |
+
dna_healthtech_articles_us_time_indexed_resampled=pd.read_csv(os.path.join(dna_folder, 'dna_healthtech_articles_us_time_indexed_resampled.tsv'),sep='\t',header=0)
|
108 |
+
dna_healthtech_articles_eu_us_time_indexed_resampled=pd.read_csv(os.path.join(dna_folder, 'dna_healthtech_articles_eu_us_time_indexed_resampled.tsv'),sep='\t',header=0)
|
109 |
+
|
110 |
+
def read_top_ent_maps():
|
111 |
+
reader = csv.reader(open(os.path.join(dna_folder, 'sorted_ent_freq_map_eu.tsv'), 'r'), delimiter='\t')
|
112 |
+
for row in reader:
|
113 |
+
k,v = row
|
114 |
+
lista = ast.literal_eval(v)
|
115 |
+
dizionario = dict()
|
116 |
+
for pair in lista:
|
117 |
+
dizionario[pair[0]]=pair[1]
|
118 |
+
dizionario = sorted(dizionario.items(), key=lambda x: x[1], reverse=True)
|
119 |
+
ent_freq_maps_eu[k]=dizionario
|
120 |
+
|
121 |
+
reader = csv.reader(open(os.path.join(dna_folder, 'sorted_ent_freq_map_us.tsv'), 'r'), delimiter='\t')
|
122 |
+
for row in reader:
|
123 |
k, v = row
|
124 |
+
lista = ast.literal_eval(v)
|
125 |
+
dizionario = dict()
|
126 |
+
for pair in lista:
|
127 |
+
dizionario[pair[0]] = pair[1]
|
128 |
+
dizionario = sorted(dizionario.items(), key=lambda x: x[1], reverse=True)
|
129 |
+
ent_freq_maps_us[k] = dizionario
|
130 |
+
|
131 |
+
reader = csv.reader(open(os.path.join(dna_folder, 'sorted_ent_freq_map_eu_us.tsv'), 'r'), delimiter='\t')
|
132 |
+
for row in reader:
|
133 |
k, v = row
|
134 |
+
lista = ast.literal_eval(v)
|
135 |
+
dizionario = dict()
|
136 |
+
for pair in lista:
|
137 |
+
dizionario[pair[0]] = pair[1]
|
138 |
+
dizionario = sorted(dizionario.items(), key=lambda x: x[1], reverse=True)
|
139 |
+
ent_freq_maps_eu_us[k] = dizionario
|
140 |
+
|
141 |
+
ent_freq_maps_eu = dict()
|
142 |
+
ent_freq_maps_us = dict()
|
143 |
+
ent_freq_maps_eu_us = dict()
|
144 |
+
|
145 |
+
read_top_ent_maps()
|
146 |
+
|
147 |
+
|
148 |
+
def read_type_filtered_triples():
|
149 |
+
for t in top_type_filtered_eu:
|
150 |
+
df = pd.read_csv(dna_folder+'/filtered_rows/eu/'+t.replace(':','_')+'.tsv', sep=" ", header=0)
|
151 |
+
df.drop(columns=['Unnamed: 0'], inplace=True)
|
152 |
+
top_type_filtered_triples_eu[t]=df
|
153 |
+
for t in top_type_filtered_us:
|
154 |
+
df = pd.read_csv(dna_folder+'/filtered_rows/us/'+t.replace(':','_')+'.tsv', sep=" ")
|
155 |
+
df.drop(columns=['Unnamed: 0'], inplace=True)
|
156 |
+
top_type_filtered_triples_us[t]=df
|
157 |
+
for t in top_type_filtered_eu_us:
|
158 |
+
df = pd.read_csv(dna_folder+'/filtered_rows/eu_us/'+t.replace(':','_')+'.tsv', sep=" ")
|
159 |
+
df.drop(columns=['Unnamed: 0'], inplace=True)
|
160 |
+
top_type_filtered_triples_eu_us[t]=df
|
161 |
+
|
162 |
+
|
163 |
+
|
164 |
+
top_type_filtered_triples_eu = dict()
|
165 |
+
top_type_filtered_triples_us = dict()
|
166 |
+
top_type_filtered_triples_eu_us = dict()
|
167 |
+
|
168 |
+
read_type_filtered_triples()
|
169 |
+
|
170 |
+
grouping_filtered = pd.read_csv(os.path.join(dna_folder, 'dna_relations.tsv'), sep=" ")
|
171 |
+
################################# CREATE CHARTS ############################
|
172 |
+
def create_curve_chart():
|
173 |
+
# Create the 3 line plots
|
174 |
+
curve_eu = hv.Curve((dh_ration_df_eu.index, dh_ration_df_eu.ids/dna_articles_unfiltered_eu_time_indexed_resampled.ids), 'Time', 'Digital Health News Ratio',label='EU')
|
175 |
+
curve_us = hv.Curve((dh_ration_df_us.index, dh_ration_df_us.ids/dna_articles_unfiltered_us_time_indexed_resampled.ids),'Time', 'Digital Health News Ratio', label='US')
|
176 |
+
curve_eu_us = hv.Curve((dh_ration_df_eu_us.index, dh_ration_df_eu_us.ids/dna_articles_unfiltered_eu_us_time_indexed_resampled.ids),'Time', 'Digital Health News Ratio', label='EU-US')
|
177 |
+
#Overlay the line plots
|
178 |
+
overlay = curve_eu * curve_us * curve_eu_us
|
179 |
+
overlay.opts(show_legend = True, legend_position='top_left', width=1200, height=600)
|
180 |
+
return overlay
|
181 |
+
|
182 |
+
|
183 |
+
def create_bar_charts(region, **kwargs):
|
184 |
+
if region=='eu':
|
185 |
+
sliced = sorted_ent_type_freq_map_eu
|
186 |
+
return hv.Bars(sliced, hv.Dimension('Entity Types'), 'Frequency').opts( framewise=True, xrotation=45,width=1200, height=600)
|
187 |
+
elif region=='us':
|
188 |
+
sliced = sorted_ent_type_freq_map_us
|
189 |
+
return hv.Bars(sliced, hv.Dimension('Entity Types'), 'Frequency').opts(framewise=True, xrotation=45,width=1200, height=600)
|
190 |
+
elif region=='eu_us':
|
191 |
+
sliced = sorted_ent_type_freq_map_eu_us
|
192 |
+
return hv.Bars(sliced, hv.Dimension('Entity Types'), 'Frequency').opts(framewise=True, xrotation=45,width=1200, height=600)
|
193 |
+
|
194 |
+
|
195 |
+
|
196 |
+
# Define a function to generate Curve based on selected values
|
197 |
+
def generate_entity_curves(region_value, type_value, **kwargs):
|
198 |
+
if region_value=='eu':
|
199 |
+
top20Ents = ent_freq_maps_eu[type_value]
|
200 |
+
curveList = []
|
201 |
+
for ent in top20Ents:
|
202 |
+
entityTriples = top_type_filtered_triples_eu[type_value][(top_type_filtered_triples_eu[type_value]['subjEntityLinks']==ent[0]) | (top_type_filtered_triples_eu[type_value]['objEntityLinks']==ent[0])]
|
203 |
+
entityTriples_time_indexed = entityTriples.set_index(pd.DatetimeIndex(entityTriples['timestamp']), inplace=False)
|
204 |
+
del entityTriples_time_indexed['timestamp']
|
205 |
+
entityTriples_time_indexed_resampled = entityTriples_time_indexed.resample("Y").count()
|
206 |
+
#print(entityTriples_time_indexed_resampled)
|
207 |
+
entityTriples_time_indexed_resampled = entityTriples_time_indexed_resampled.reindex(dna_healthtech_articles_eu_time_indexed_resampled.index, fill_value=0)
|
208 |
+
curve = hv.Curve((entityTriples_time_indexed_resampled.index, (entityTriples_time_indexed_resampled['doc_id']/dna_healthtech_articles_eu_time_indexed_resampled['ids'])), 'Time', 'Key Entity Occurrence', label=ent[0])
|
209 |
+
curve.opts(autorange='y')
|
210 |
+
#curve.opts(logy=True)
|
211 |
+
curveList.append(curve)
|
212 |
+
overlay = hv.Overlay(curveList)
|
213 |
+
overlay.opts(legend_muted=False, legend_cols=4, show_legend = True, legend_position='top_left', fontsize={'legend':13},width=1200, height=800)
|
214 |
+
return overlay
|
215 |
+
|
216 |
+
elif region_value=='us':
|
217 |
+
top20Ents = ent_freq_maps_us[type_value]
|
218 |
+
curveList = []
|
219 |
+
for ent in top20Ents:
|
220 |
+
entityTriples = top_type_filtered_triples_us[type_value][(top_type_filtered_triples_us[type_value]['subjEntityLinks']==ent[0]) | (top_type_filtered_triples_us[type_value]['objEntityLinks']==ent[0])]
|
221 |
+
entityTriples_time_indexed = entityTriples.set_index(pd.DatetimeIndex(entityTriples['timestamp']), inplace=False)
|
222 |
+
del entityTriples_time_indexed['timestamp']
|
223 |
+
entityTriples_time_indexed_resampled = entityTriples_time_indexed_resampled.reindex(dna_healthtech_articles_us_time_indexed_resampled.index, fill_value=0)
|
224 |
+
curve = hv.Curve((entityTriples_time_indexed_resampled.index, (entityTriples_time_indexed_resampled['doc_id']/dna_healthtech_articles_us_time_indexed_resampled['ids'])), 'Time', 'Key Entity Occurrence', label=ent[0])
|
225 |
+
curve.opts(autorange='y')
|
226 |
+
curveList.append(curve)
|
227 |
+
overlay = hv.Overlay(curveList)
|
228 |
+
overlay.opts(legend_muted=False, legend_cols=4, show_legend = True, legend_position='top_left', fontsize={'legend':13},width=1200, height=800)
|
229 |
+
return overlay
|
230 |
+
|
231 |
+
elif region_value=='eu_us':
|
232 |
+
top20Ents = ent_freq_maps_eu_us[type_value]
|
233 |
+
curveList = []
|
234 |
+
for ent in top20Ents:
|
235 |
+
entityTriples = top_type_filtered_triples_eu_us[type_value][(top_type_filtered_triples_eu_us[type_value]['subjEntityLinks']==ent[0]) | (top_type_filtered_triples_eu_us[type_value]['objEntityLinks']==ent[0])]
|
236 |
+
entityTriples_time_indexed = entityTriples.set_index(pd.DatetimeIndex(entityTriples['timestamp']), inplace=False)
|
237 |
+
del entityTriples_time_indexed['timestamp']
|
238 |
+
entityTriples_time_indexed_resampled = entityTriples_time_indexed_resampled.reindex(dna_healthtech_articles_eu_us_time_indexed_resampled.index, fill_value=0)
|
239 |
+
curve = hv.Curve((entityTriples_time_indexed_resampled.index, (entityTriples_time_indexed_resampled['doc_id']/dna_healthtech_articles_eu_us_time_indexed_resampled['ids'])), 'Time', 'Key Entity Occurrence', label=ent[0])
|
240 |
+
curve.opts(autorange='y')
|
241 |
+
curveList.append(curve)
|
242 |
+
overlay = hv.Overlay(curveList)
|
243 |
+
overlay.opts(legend_muted=False, legend_cols=4, show_legend = True, legend_position='top_left', fontsize={'legend':13},width=1200, height=800)
|
244 |
+
return overlay
|
245 |
+
|
246 |
+
|
247 |
+
############################# WIDGETS & CALLBACK ###########################################
|
248 |
+
|
249 |
+
def filter_data0(df, min_value):
|
250 |
+
filtered_df = df[df['value'] >= min_value]
|
251 |
+
return filtered_df
|
252 |
+
|
253 |
+
|
254 |
+
def plot_chord0_new(df,min_value):
|
255 |
+
filtered_df = filter_data0(df, min_value)
|
256 |
+
# Create a Holoviews Dataset for nodes
|
257 |
+
nodes = hv.Dataset(filtered_df, 'index')
|
258 |
+
nodes.data.head()
|
259 |
+
chord = hv.Chord(filtered_df, ['source', 'target'], ['value'])
|
260 |
+
return chord.opts(opts.Chord(cmap='Category20', edge_cmap='Category20', label_text_color="white", node_color = hv.dim('index').str(), edge_color = hv.dim('source').str(), labels = 'index', tools=['hover'], width=800, height=800))
|
261 |
+
|
262 |
+
|
263 |
+
def retrieveRegionTypes(region):
|
264 |
+
if region == 'eu':
|
265 |
+
return top_type_filtered_eu
|
266 |
+
elif region == 'us':
|
267 |
+
return top_type_filtered_us
|
268 |
+
elif region == 'eu_us':
|
269 |
+
return top_type_filtered_eu_us
|
270 |
+
|
271 |
+
|
272 |
+
def filter_region(region):
|
273 |
+
if region == 'eu':
|
274 |
+
region_grouping = grouping_filtered[grouping_filtered['region'] == 'eu']
|
275 |
+
elif region == 'us':
|
276 |
+
region_grouping = grouping_filtered[grouping_filtered['region'] == 'us']
|
277 |
+
elif region == 'eu_us':
|
278 |
+
region_grouping = grouping_filtered[grouping_filtered['region'] == 'eu_us']
|
279 |
+
|
280 |
+
#print(len(region_grouping))
|
281 |
+
# Define range for minimum value slider
|
282 |
+
min_value_range = region_grouping['value'].unique()
|
283 |
+
min_value_range.sort()
|
284 |
+
|
285 |
+
# Define HoloMap with minimum value and attribute as key dimensions
|
286 |
+
holomap = hv.HoloMap({min_value: plot_chord0_new(region_grouping, min_value)
|
287 |
+
for min_value in min_value_range},
|
288 |
+
kdims=['Show triples with support greater than']
|
289 |
+
)
|
290 |
+
return holomap
|
291 |
+
|
292 |
+
|
293 |
+
# Define a function to generate Entity List RadioButtonGroup based on Region selection
|
294 |
+
def generate_radio_buttons(value):
|
295 |
+
if value == 'eu':
|
296 |
+
return pn.widgets.RadioButtonGroup(options=retrieveRegionTypes(value), value='DBpedia:Company', name='eu', orientation='vertical')
|
297 |
+
elif value == 'us':
|
298 |
+
return pn.widgets.RadioButtonGroup(options=retrieveRegionTypes(value), value='DBpedia:Disease', name='us', orientation='vertical')
|
299 |
+
elif value == 'eu_us':
|
300 |
+
return pn.widgets.RadioButtonGroup(options=retrieveRegionTypes(value), value='DBpedia:Person', name='eu_us', orientation='vertical')
|
301 |
+
|
302 |
+
|
303 |
+
|
304 |
+
# https://tabler-icons.io/
|
305 |
+
button1 = pn.widgets.Button(name="Introduction", button_type="warning", icon="file-info", styles={"width": "100%"})
|
306 |
+
button2 = pn.widgets.Button(name="AECO Macro Topics", button_type="warning", icon="chart-histogram", styles={"width": "100%"})
|
307 |
+
#button3 = pn.widgets.Button(name="Top Entity Types", button_type="warning", icon="chart-bar", styles={"width": "100%"})
|
308 |
+
#button4 = pn.widgets.Button(name="Top Key Entities", button_type="warning", icon="chart-dots-filled", styles={"width": "100%"})
|
309 |
+
#button5 = pn.widgets.Button(name="Entity Chord Diagrams", button_type="warning", icon="chart-dots-filled", styles={"width": "100%"})
|
310 |
+
#button3 = pn.widgets.Button(name="Research Collaboration Networks: Institutes", button_type="warning", icon="chart-dots-3", styles={"width": "100%"})
|
311 |
+
#button4 = pn.widgets.Button(name="Research Collaboration Networks: Authors", button_type="warning", icon="chart-dots-3", styles={"width": "100%"})
|
312 |
+
|
313 |
+
|
314 |
+
region1 = pn.widgets.RadioButtonGroup(name='### Select News Region', options=regions)
|
315 |
+
|
316 |
+
macro_topics_button = pn.widgets.RadioButtonGroup(name='### Select Macro Topic', value='Energy-Efficient Building Design for Thermal Comfort and Sustainability', options=macro_topics)
|
317 |
+
|
318 |
+
|
319 |
+
# Initial RadioButtonGroup
|
320 |
+
radio_buttons_regions = pn.widgets.RadioButtonGroup(options=regions,value='eu',name='Select region')
|
321 |
+
# Generate initial dynamic RadioButtonGroup
|
322 |
+
radio_buttons_types = generate_radio_buttons(radio_buttons_regions.value)
|
323 |
+
|
324 |
+
|
325 |
+
|
326 |
+
# Define a callback function to update the panel dynamically
|
327 |
+
def update_radio_group(event):
|
328 |
+
#print(event.new)
|
329 |
+
#print(retrieveRegionTypes(event.new))
|
330 |
+
radio_buttons_types.options = retrieveRegionTypes(event.new)
|
331 |
+
|
332 |
+
|
333 |
+
# bind the function to the widget(s)
|
334 |
+
dmap2 = hv.DynamicMap(pn.bind(generate_entity_curves, radio_buttons_regions,radio_buttons_types))
|
335 |
+
# Bind the selected value of the first RadioButtonGroup to update the second RadioButtonGroup
|
336 |
+
radio_buttons_regions.param.watch(update_radio_group, 'value')
|
337 |
+
|
338 |
+
# Define the callback function to update the HoloMap
|
339 |
+
def update_holomap(event):
|
340 |
+
initial_holomap.object = filter_region(event.new)
|
341 |
+
|
342 |
+
region_radio_button = pn.widgets.RadioButtonGroup(options=regions, value='eu', name='Select Region')
|
343 |
+
|
344 |
+
# Create the initial HoloMap
|
345 |
+
initial_holomap = filter_region(region_radio_button.value)
|
346 |
+
|
347 |
+
# Bind the callback function to the value change event of the RadioButton widget
|
348 |
+
region_radio_button.param.watch(update_holomap, 'value')
|
349 |
+
|
350 |
+
|
351 |
+
|
352 |
+
def show_page(page_key):
|
353 |
+
main_area.clear()
|
354 |
+
main_area.append(mapping[page_key])
|
355 |
+
|
356 |
+
button1.on_click(lambda event: show_page("Page1"))
|
357 |
+
button2.on_click(lambda event: show_page("Page2"))
|
358 |
+
#button3.on_click(lambda event: show_page("Page3"))
|
359 |
+
#button4.on_click(lambda event: show_page("Page4"))
|
360 |
+
#button5.on_click(lambda event: show_page("Page5"))
|
361 |
+
#button6.on_click(lambda event: show_page("Page6"))
|
362 |
+
|
363 |
+
|
364 |
+
### CREATE PAGE LAYOUTS
|
365 |
+
|
366 |
+
def CreatePage1():
|
367 |
+
return pn.Column(pn.pane.Markdown("""
|
368 |
+
|
369 |
+
This is a dashboard for a Research Analysis project regarding research and technology in the AECO domain. The source data consists of around
|
370 |
+
276k English-language research papers gathered from the openalex.org graph database, covering a timeframe from 2011 through 2024.
|
371 |
+
|
372 |
+
---------------------------
|
373 |
+
|
374 |
+
## 1. AECO Macro Topics
|
375 |
+
In the AECO Macro Topics panel we present the 6-month-sampled time series depicting the number of published research papers
|
376 |
+
for the 16 macro-topics automatically detected by an optimized BerTopic model and ppst-processed for manual topic merging.
|
377 |
+
|
378 |
+
|
379 |
+
### 2. Research Collaboration Networks: Institutes
|
380 |
+
|
381 |
+
### 3. Research Collaboration Networks: Authors
|
382 |
+
""", width=800), align="center")
|
383 |
+
|
384 |
+
def CreatePage2():
|
385 |
+
# Load the HTML content from the local file
|
386 |
+
#with open(AECO_topics_over_time_file_path, 'r', encoding='utf-8') as file:
|
387 |
+
# html_content = file.read()
|
388 |
+
# Use an iframe to load the local HTML file
|
389 |
+
iframe_html = f'<iframe src="{AECO_topics_over_time_file_path}" width="100%" height="600px"></iframe>'
|
390 |
+
# Create an HTML pane to render the content
|
391 |
+
html_pane = pn.pane.HTML(iframe_html , sizing_mode='stretch_width')
|
392 |
+
return pn.Column(pn.pane.Markdown(" ## AECO Macro Topics "), html_pane, align="center")
|
393 |
+
|
394 |
+
def CreatePage3():
|
395 |
+
return pn.Column(
|
396 |
+
macro_topics_button,
|
397 |
+
pn.bind(create_bar_charts, region1),
|
398 |
+
align="center",
|
399 |
+
)
|
400 |
+
|
401 |
+
def CreatePage4():
|
402 |
+
return pn.Column(
|
403 |
+
pn.pane.Markdown("## Top Key Entities "),
|
404 |
+
pn.Row(pn.Column(radio_buttons_regions, radio_buttons_types), dmap2),
|
405 |
+
align="center", )
|
406 |
+
|
407 |
+
def CreatePage5():
|
408 |
+
return pn.Column(
|
409 |
+
pn.pane.Markdown("## Entity Chord Diagrams "),
|
410 |
+
pn.Row(region_radio_button, pn.bind(filter_region, region_radio_button)),
|
411 |
+
align="center", )
|
412 |
+
|
413 |
+
|
414 |
+
def CreatePage6():
|
415 |
+
html = """<iframe src="https://app.vosviewer.com/?json=https%3A%2F%2Fdrive.google.com%2Fuc%3Fid%3D16q1oLQyEeMosAgeD9UkC9hSrpzAYX_-n" width="800" height="800"></iframe>"""
|
416 |
+
|
417 |
+
html_pane = pn.pane.HTML(html)
|
418 |
+
#url = 'https://app.vosviewer.com/?json=https%3A%2F%2Fdrive.google.com%2Fuc%3Fid%3D16q1oLQyEeMosAgeD9UkC9hSrpzAYX_-n'
|
419 |
+
return html_pane
|
420 |
+
#panel.show()
|
421 |
+
#return pn.Column(
|
422 |
+
# pn.pane.Markdown("## VOSViewer Network "),
|
423 |
+
# pn.Row(panel)
|
424 |
+
# )
|
425 |
+
|
426 |
+
|
427 |
+
mapping = {
|
428 |
+
"Page1": CreatePage1(),
|
429 |
+
"Page2": CreatePage2(),
|
430 |
+
#"Page3": CreatePage3(),
|
431 |
+
#"Page4": CreatePage4(),
|
432 |
+
#"Page5": CreatePage5(),
|
433 |
+
"Page6": CreatePage6()
|
434 |
+
}
|
435 |
+
|
436 |
+
#################### SIDEBAR LAYOUT ##########################
|
437 |
+
sidebar = pn.Column(pn.pane.Markdown("## Pages"), button1,button2,#button3,
|
438 |
+
#button4,
|
439 |
+
#button5,
|
440 |
+
#button6,
|
441 |
+
styles={"width": "100%", "padding": "15px"})
|
442 |
+
|
443 |
+
#################### MAIN AREA LAYOUT ##########################
|
444 |
+
main_area = pn.Column(mapping["Page1"], styles={"width":"100%"})
|
445 |
+
|
446 |
+
###################### APP LAYOUT ##############################
|
447 |
+
template = pn.template.BootstrapTemplate(
|
448 |
+
title=" AECO Tech Dashboard",
|
449 |
+
sidebar=[sidebar],
|
450 |
+
main=[main_area],
|
451 |
+
header_background="black",
|
452 |
+
#site="Charting the Landscape of AECO Research",
|
453 |
+
theme=pn.template.DarkTheme,
|
454 |
+
sidebar_width=250, ## Default is 330
|
455 |
+
busy_indicator=pn.indicators.BooleanStatus(value=True),
|
456 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
457 |
|
458 |
+
### DEPLOY APP
|
459 |
+
|
460 |
+
# Serve the Panel app
|
461 |
+
template.servable()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
462 |
|
463 |
+
if __name__ == "__main__":
|
464 |
+
app.run(host="0.0.0.0", port=7860)
|