thanks for the offer to help! here is an explicit example:
$ tree audio
audio
├── main.py
└── templates
└── index.html
1 directory, 2 files
$ cat main.py
from bokeh.plotting import curdoc
from bokeh.layouts import row, widgetbox
from bokeh.models.widgets import Button
from bokeh.events import ButtonClick
from bokeh.models.callbacks import CustomJS
import logging
bokehlog = logging.getLogger("deepsong")
bokehlog.setLevel(logging.INFO)
play_audio = Button(label='play audio')
play_audio.js_on_event(ButtonClick, \
CustomJS(args=dict(fakedata="hide-and-seek"),
code="""
var aud = document.getElementById("audio_tag");
aud.src="data:audio/wav;base64,"+fakedata;
aud.play();
"""))
def change_audio_callback():
bokehlog.info("entering `change_audio_callback`")
play_audio.js_on_event(ButtonClick, \
CustomJS(args=dict(fakedata="peek-a-boo"),
code="""
var aud = document.getElementById("audio_tag");
aud.src="data:audio/wav;base64,"+fakedata;
aud.play();
"""))
change_audio = Button(label='change audio')
change_audio.on_click(change_audio_callback)
curdoc().add_root(row(play_audio, change_audio))
$ cat templates/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
{{ bokeh_css }}
{{ bokeh_js }}
<link rel="stylesheet" href="gui/static/css/styles.css"/>
</head>
<body>
<audio id="audio_tag" controls></audio>
{{ plot_div|indent(8) }}
{{ plot_script|indent(8) }}
</body>
</html>
to serve i use:
# bokeh serve --allow-websocket-origin=`hostname`:5006 --allow-websocket-origin=localhost:5006 --port 5006 --show audio
i then open chrome, navigate to “localhost:5006”, open the javascript console, click on Elements, and examine the DOM of the audio HTML tag. initially it has no src field. when i click on the bokeh “play audio” button, the audio src field appears and is set to data:audio/wav;base64,hide-and-seek, as expected. i then click “change audio” and confirm that "entering change_audio_callback" is logged. then i click on “play audio” again, and though the audio tag line in the Elements window blinks to indicate is has been updated, the src field remains “hide-and-seek” instead of changing to “peek-a-boo”.