CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
| Download
Dash plot visualization from CoCalc project
Project: 📚MOOC Studies
Path: DASH/dash-demo.py
Views: 1447Image: ubuntu2004
# Demo of Dash in a CoCalc project1# Dash tutorial:2# https://dash.plot.ly/getting-started3# CoCalc HTTP server from a project4# https://doc.cocalc.com/howto/webserver.html5# Blog articles about Dash with CoCalc6# REVISED: https://blog.cocalc.com/cocalc/python/2021/05/03/dash-with-cocalc.html7# OUTDATED: https://blog.cocalc.com/cocalc/python/2018/06/08/dash-with-cocalc.html8#9# 1. Run this file from a .term:10# python3 dash-demo.py11# 2. When the program runs in the terminal, it will print a URL like this:12# https://cocalc.com/<your project id>/server/999013# i.e. if your project id is 30b9a512-6b2c-11e8-a361-4f5344355d2c, the link would be14# https://cocalc.com/30b9a512-6b2c-11e8-a361-4f5344355d2c/server/999015# Open a new browser tab to the link that is printed.1617# You must be a collaborator on the project and logged into your CoCalc account18# to view the application.1920import dash21import dash_core_components as dcc22import dash_html_components as html2324import os25cocalc_project_id = os.environ['COCALC_PROJECT_ID']26port = 999027pfx = "/{}/server/{}/".format(cocalc_project_id, port)28app = dash.Dash(requests_pathname_prefix = pfx)2930app.layout = html.Div(children=[31html.H1(children='Hello Dash from CoCalc'),3233html.Div(children='''34Dash: A web application framework for Python.35'''),3637dcc.Graph(38id='example-graph',39figure={40'data': [41{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},42{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},43],44'layout': {45'title': 'Dash Data Visualization'46}47}48)49])50515253if __name__ == '__main__':54print("browse to: https://cocalc.com{}".format(pfx))55app.run_server(debug=True, port=port, host='0.0.0.0')5657