Hi all,
I am quite novice at bokeh but I am starting to get the hang of it.
I created a function which allowed users to extract a csv from a plot using a Button.
I created an adaptation to the code from stack overflow:
It was working in the past, however, now since 2.1.1 the button.callback does not seem to work.
from bokeh.models import ColumnDataSource, CustomJS
from bokeh.models.widgets import Button
from bokeh.io import show
source = ColumnDataSource({'list1':[0,1,2,3],'list2':[4,5,6,7]})
button = Button(label="Download", button_type="success")
javaScript="""
function table_to_csv(source) {
const columns = Object.keys(source.data)
const nrows = source.get_length()
const lines = [columns.join(',')]
for (let i = 0; i < nrows; i++) {
let row = [];
for (let j = 0; j < columns.length; j++) {
const column = columns[j]
row.push(source.data[column][i].toString())
}
lines.push(row.join(','))
}
return lines.join('\\n').concat('\\n')
}
const filename = 'data_result.csv'
filetext = table_to_csv(source)
const blob = new Blob([filetext], { type: 'text/csv;charset=utf-8;' })
//addresses IE
if (navigator.msSaveBlob) {
navigator.msSaveBlob(blob, filename)
} else {
const link = document.createElement('a')
link.href = URL.createObjectURL(blob)
link.download = filename
link.target = '_blank'
link.style.visibility = 'hidden'
link.dispatchEvent(new MouseEvent('click'))
}
"""
button.callback = CustomJS(args=dict(source=source),code=javaScript)
show(button)
I have tried to do the following:
instead of :
button.callback = CustomJS(args=dict(source=source),code=javaScript)
I replaced it with:
button.js_on_event(ButtonClick, CustomJS(args=dict(source=source),code=javaScript))
and
button.js_on_click(CustomJS(args=dict(source=source),code=javaScript))
( I of course added the needed modules if applicable)
but with no success.
I get no errors, but whenever the button shows which I click nothing happens.
Is there anyone that has a solution to this?
Many thanks in advance!!
Kind regards.