Skip to content

BokehServer.md

Arman edited this page Jun 27, 2020 · 2 revisions

Using Cocalc Server functionality

For deploying an interactive plots based on Bokeh, Panel or similar libraries we can use similar future of the CoCalc like in the examples of the Tensorboard:

  • create a python file holo.py
import holoviews as hv
import panel as pn
import numpy as np

hv.extension('bokeh')

def sine(frequency, phase, amplitude):
    xs = np.linspace(0, np.pi*4)
    return hv.Curve((xs, np.sin(frequency*xs+phase)*amplitude)).options(width=800)

if __name__ == '__main__':
    ranges = dict(frequency=(1, 5), phase=(-np.pi, np.pi), amplitude=(-2, 2), y=(-2, 2))
    dmap = hv.DynamicMap(sine, kdims=['frequency', 'phase', 'amplitude']).redim.range(**ranges)
    pn.serve(dmap, port=8006, allow_websocket_origin=["cocalc.com"], show=False)
  • replace cocalc.com to your domain if you are using the self hosted instance.
  • in the terminal:
python holo.py
  • now your interactive Holoview application is available in the following URL:
https://cocalc.com/PROJECT_ID/server/8006/
Clone this wiki locally