SharedDASH / dash-demo.pyOpen in CoCalc
Authors: Hal Snyder, ℏal Snyder
Views : 15
Description: Dash plot visualization from CoCalc project
1
# Demo of Dash in a CoCalc project
2
# Dash tutorial:
3
# https://dash.plot.ly/getting-started
4
# CoCalc HTTP server from a project
5
# https://github.com/sagemathinc/cocalc/wiki/HTTPWebserver
6
#
7
# 1. Run this file from a .term:
8
# python3 dash-demo.py
9
# 2. When the program runs in the terminal, it will print a URL like this:
10
# https://cocalc.com/<your project id>/server/9990
11
# i.e. if your project id is 30b9a512-6b2c-11e8-a361-4f5344355d2c, the link would be
12
# https://cocalc.com/30b9a512-6b2c-11e8-a361-4f5344355d2c/server/9990
13
# Open a new browser tab to the link that is printed.
14
15
# You must be a collaborator on the project and logged into your CoCalc account
16
# to view the application.
17
18
import dash
19
import dash_core_components as dcc
20
import dash_html_components as html
21
22
app = dash.Dash()
23
24
app.layout = html.Div(children=[
25
html.H1(children='Hello Dash from CoCalc'),
26
27
html.Div(children='''
28
Dash: A web application framework for Python.
29
'''),
30
31
dcc.Graph(
32
id='example-graph',
33
figure={
34
'data': [
35
{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
36
{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
37
],
38
'layout': {
39
'title': 'Dash Data Visualization'
40
}
41
}
42
)
43
])
44
45
port = 9990
46
47
import os
48
cocalc_project_id = os.environ['COCALC_PROJECT_ID']
49
50
pfx = "/{}/server/{}/".format(cocalc_project_id, port)
51
app.config.requests_pathname_prefix = pfx
52
53
if __name__ == '__main__':
54
print("browse to: https://cocalc.com{}".format(pfx))
55
app.run_server(debug=True, port=port, host='0.0.0.0')