Open james-pcdr opened 6 months ago
I think Bokeh meets our needs more than Plotly/Dash because Bokeh's data-update feels more natural (IMO).
'''
Source:
https://demo.bokeh.org/sliders
https://github.com/bokeh/bokeh/blob/main/examples/server/app/sliders.py
Present an interactive function explorer with slider widgets.
Use the ``bokeh serve`` command to run the example by executing:
bokeh serve sliders.py
at your command prompt. Then navigate to the URL
http://localhost:5006/sliders
in your browser.
'''
import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import column, row
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure
# Set up data
N = 2000
x = np.linspace(0, 4, N)
y = np.zeros_like(x)
source = ColumnDataSource(data=dict(x=x, y=y))
rng = np.random.default_rng()
# Set up plot
plot = figure(height=400, width=400, title="My sine wave",
tools="crosshair,pan,reset,save,wheel_zoom",
x_range=[0, 4], y_range=[-2.5, 2.5])
plot.line('x', 'y', source=source)
# Set up widgets
amplitude = Slider(title="amplitude", value=1.0, start=-5.0, end=5.0, step=0.1)
freq = Slider(title="frequency", value=1.0, start=0.1, end=5.1, step=0.1)
# Set up callbacks
def update_data(attrname, old, new):
# Get the current slider values
a = amplitude.value
k = freq.value
# Generate the new curve
noise = rng.normal(0, 0.1, N)
y = a*np.sin(k*2*np.pi*x) + noise
source.data = dict(x=x, y=y)
amplitude.on_change('value', update_data)
freq.on_change('value', update_data)
# Set up layouts and add to document
inputs = column(amplitude, freq)
curdoc().add_root(row(inputs, plot, width=800))
curdoc().title = "Sliders"
# Set up automatic updates
curdoc().add_periodic_callback(lambda: update_data(None, None, None), 50)
Random old disorganized notes to self:
We want to ...
Constraints:
Notes:
I think we want...
Leaning towards Bokeh because it looks un commercial ish
https://plotly.com/compare-dash-shiny-streamlit-bokeh/ See also seaborne (if that is web able)
We could try using gr-bokehgui; not sure how hard that would be to set up given our classroom software constraints.
Plotly / Dash is another option.