I have successfully embedded a Bokeh script in my Flask framework (based on the wonderful example) but am looking to add some functionality via forms and URL-args.
Specifically, I want to be able to select points to be “removed” from the dataset. Right now I have achieved this by having a form field which requires manual input of sample names, then submit the names (along with other form data) as URL.
What I would really like, however, is this form field to updated automatically, such that selecting points will send their names as URL-args back to the server (where they can be removed).
Does anyone know how this would be accomplished? Perhaps through a JS updated form (or is this what Callbacks are for?)
And here is the source for my view. It really is just a viewer for principal component analyses.
def flask_pca(filename=None): # Get all the form arguments if filename is None: args = flask.request.args remove = getitem(args, 'remove', '') filename = getitem(args, 'filename', '') else: remove = '' if len(remove) > 1: remove = remove.split(';') remove = [item for item in remove if item != u''] # load our data from a saved file file_path_name = os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], filename) df = pd.read_csv(file_path_name, index_col=0) # generate a boolean index to keep items we don't want to remove bool_key = [item not in remove for item in df.index] df = df.loc[bool_key, :] data = df.values #PCA calculations sklearn_pca = sklearnPCA() Y_sklearn = sklearn_pca.fit_transform(data) hover = HoverTool( tooltips=[ ("Sample Name", "@desc") ] ) TOOLS = "crosshair,pan,wheel_zoom,box_zoom,reset,previewsave,box_select" source = ColumnDataSource( data=dict( x=Y_sklearn[:, 0], y=Y_sklearn[:, 1], desc=list(df.index) ) ) fig = figure(title="PCA", tools=[TOOLS, hover]) fig.circle('x', 'y', source=source, fill_alpha=0.2, size=10) js_resources = INLINE.render_js() css_resources = INLINE.render_css() script, div = components(fig, INLINE) remove_str = "" for item in remove: remove_str += item + ";" html = render_template( 'embed.html', plot_script=script, plot_div=div, js_resources=js_resources, css_resources=css_resources, filename=filename, remove=remove_str ) return html