-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (36 loc) · 1.57 KB
/
main.py
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
47
48
49
#Displays results of q9-sankey.sparql query via <none> graph located at https://labs.tib.eu/sdm/coy/sparql endpoint
from dash import Dash, dcc, html, Input, Output
import plotly.graph_objects as go
import json, urllib
def print_hi(name):
print(f'Hi, {name}')
if __name__ == '__main__':
print_hi('TIB colleagues:')
app = Dash(__name__)
app.layout = html.Div([
html.H4('First twenty highest exports between value added origin countries and final demand EU countries for "Basic metals" and "Fabricated metal products" industry sectors'),
dcc.Graph(id="graph"),
html.P("Opacity"),
dcc.Slider(id='slider', min=0, max=1,
value=0.5, step=0.1)
])
@app.callback(
Output("graph", "figure"),
Input("slider", "value"))
def display_sankey(opacity):
#url = 'https://raw.githubusercontent.com/plotly/plotly.js/master/test/image/mocks/sankey_energy.json'
url = 'https://raw.githubusercontent.com/nenadkrdzavac/mapping-trade-in-value-added/master/src/main/resources/sparql_results/q9-sankey-limited.json'
response = urllib.request.urlopen(url)
data = json.loads(response.read()) # replace with your own data source
node = data['data'][0]['node']
node['color'] = [
f'rgba(255,0,255,{opacity})'
if c == "magenta" else c.replace('0.8', str(opacity))
for c in node['color']]
link = data['data'][0]['link']
link['color'] = [
node['color'][src] for src in link['source']]
fig = go.Figure(go.Sankey(link=link, node=node))
fig.update_layout(font_size=10)
return fig
app.run_server(debug=True)