我想做这样的事情。我创建了一些小部件,例如一个下拉列表、一个多选框和一个文本输入框。然后我添加一个按钮。当用户在小部件中选择变量并单击按钮时。他们选择的值将作为 txt 文件下载。我希望这个 html 可以在没有散景服务器的情况下使用,所以如果有人可以通过 customJS 完成它,我将不胜感激。真的很感激。from random import randomfrom bokeh.plotting import figure, output_file, show, ColumnDataSourcefrom bokeh.models import CustomJS, Buttonfrom bokeh.layouts import row, columnsavebutton = Button(label="Save", button_type="success")savebutton.callback = CustomJS(args=dict(multi_select1.value,multi_select2.value), code=""" var value1 = multi_select1.value; var value2 = multi_select1.value; var out = ""; for (i = 0; i < value1.length; i++) { out += value1[i]; } for (i = 0; i < value2.length; i++) { out += value2[i]; } var file = new Blob([out], {type: 'text/plain'}); var elem = window.document.createElement('a'); elem.href = window.URL.createObjectURL(file); elem.download = 'selected-data.txt'; document.body.appendChild(elem); elem.click(); document.body.removeChild(elem); """)assets=['asset1','asset2','asset3','asset4']multi_select1 = MultiSelect(title="Select:", value=['asset1'],options=assets, height=200, width=100)multi_select2 = MultiSelect(title="Select:", value=['asset1'],options=assets, height=200, width=100)plot = column(multi_select1,multi_select2,savebutton)show(plot)
添加回答
举报
0/150
提交
取消