# Demo of Dash in a CoCalc project1# Dash tutorial:2# https://dash.plot.ly/getting-started3# CoCalc HTTP server from a project4# https://github.com/sagemathinc/cocalc/wiki/HTTPWebserver5#6# 1. Run this file from a .term:7# python3 dash-demo.py8# 2. When the program runs in the terminal, it will print a URL like this:9# https://cocalc.com/<your project id>/server/999010# i.e. if your project id is 30b9a512-6b2c-11e8-a361-4f5344355d2c, the link would be11# https://cocalc.com/30b9a512-6b2c-11e8-a361-4f5344355d2c/server/999012# Open a new browser tab to the link that is printed.1314# You must be a collaborator on the project and logged into your CoCalc account15# to view the application.1617import dash18import dash_core_components as dcc19import dash_html_components as html2021app = dash.Dash()2223app.layout = html.Div(children=[24html.H1(children='Hello Dash from CoCalc'),2526html.Div(children='''27Dash: A web application framework for Python.28'''),2930dcc.Graph(31id='example-graph',32figure={33'data': [34{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},35{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},36],37'layout': {38'title': 'Dash Data Visualization'39}40}41)42])4344port = 99904546import os47cocalc_project_id = os.environ['COCALC_PROJECT_ID']4849pfx = "/{}/server/{}/".format(cocalc_project_id, port)50app.config.requests_pathname_prefix = pfx5152if __name__ == '__main__':53print("browse to: https://cocalc.com{}".format(pfx))54app.run_server(debug=True, port=port, host='0.0.0.0')55